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".
Visual presentation:
Practice Online
Query Visualization:
Duration:
Rows:
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics