w3resource

SQL Exercises: Select specific columns from a table

SQL Basic Select Statement: Exercise-6 with Solution

Write a SQL statement to display specific columns such as names and commissions for all salespeople.

Sample table: salesman

 salesman_id |    name    |   city   | commission 
-------------+------------+----------+------------
        5001 | James Hoog | New York |       0.15
        5002 | Nail Knite | Paris    |       0.13
        5005 | Pit Alex   | London   |       0.11
        5006 | Mc Lyon    | Paris    |       0.14
        5007 | Paul Adam  | Rome     |       0.13
        5003 | Lauson Hen | San Jose |       0.12

Sample Solution:

-- This query selects specific columns 'name' and 'commission' from the 'salesman' table.
SELECT name, commission
-- Specifies the table from which to retrieve the data (in this case, 'salesman').
FROM salesman;

Output of the Query:

name		commission
James Hoog	0.15
Nail Knite	0.13
Pit Alex	0.11
Mc Lyon		0.14
Paul Adam	0.13
Lauson Hen	0.12

Code Explanation:

The said SQL query that selects the "name" and "commission" columns from the 'salesman' table.
The table will have columns for "name" and "commission".

Syntax of select specific columns from a table

Visual presentation:

Result of select specific columns from a table

Practice Online


Query Visualization:

Duration:

Query visualization of Select specific columns from a table - Duration

Rows:

Query visualization of Select specific columns from a table - Rows

Cost:

Query visualization of Select specific columns from a table - Cost

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous SQL Exercise: Display the result of an arithmetic expression.
Next SQL Exercise: Select the columns in different order.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/sql-exercises/sql-retrieve-exercise-6.php