Filter rows with WHERE
Question
Show the name and salary of employees who earn more than 7000.
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 |
| Priya Nair | 9200 |
| Mei Chen | 7600 |
| Hana Kim | 7300 |
Hint
WHERE keeps only the rows where the condition is true.
Show the solution
solution.sql
Run this code
SELECT name, salary
FROM employees
WHERE salary > 7000;
Why it works
WHERE is checked for every row before anything is returned. Only the four employees with a salary above 7000 pass the test.
Common mistake
"More than 7000" means > 7000. Using >= 7000 would also include someone who earns exactly 7000.