Select specific columns
Question
List the name and salary of every employee.
employeesid, name, salary, department_id, manager_id, hired_on
departmentsid, name, city
Your query
Ctrl+Enter to run
Result
Expected result
| name | salary |
|---|---|
| Tom Becker | 8800 |
| Ana Souza | 6500 |
| Priya Nair | 9200 |
| Lucas Moreau | 6800 |
| Mei Chen | 7600 |
| Omar Haddad | 5600 |
| Sofia Rossi | 6100 |
| Jonas Berg | 5400 |
| Aisha Bello | 4700 |
| Diego Ruiz | 4100 |
| Hana Kim | 7300 |
| Liam Walsh | 4300 |
Hint
Write the column names after SELECT, separated by commas.
Show the solution
solution.sql
Run this code
SELECT name, salary
FROM employees;
Why it works
Listing columns after SELECT returns only those columns, in the order you write them. The rows are the same as with SELECT *, just narrower.
Common mistake
A missing comma (SELECT name salary) does not give an error. SQL reads it as "name, renamed to salary", so you get one column instead of two.