SQL Exercises: Select specific columns from a table
Write a SQL statement to display specific columns such as names and commissions for all salespeople.
Sample table: salesmansalesman_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](https://www.w3resource.com/w3r_images/sql-retrieve-image-code6.gif)
Visual presentation:
![Result of select specific columns from a table](https://www.w3resource.com/w3r_images/sql-retrieve-image-result-6.gif)
Practice Online
For more Practice: Solve these Related Problems:
- Write a SQL query to display the names and cities of all customers.
- Write a SQL query to retrieve the product names and prices from the "products" table.
- Write a SQL query to list the employee IDs and departments from the "employees" table.
- Write a SQL query to show the supplier names and contact numbers from the "suppliers" table.
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics