Top 3 highest salaries
Question
Show the name and salary of the three best-paid employees, highest salary first.
employeesid, name, salary, department_id, manager_id, hired_on
departmentsid, name, city
Your query
Ctrl+Enter to run
Result
Expected result
| name | salary |
|---|---|
| Priya Nair | 9200 |
| Tom Becker | 8800 |
| Mei Chen | 7600 |
Hint
Sort with ORDER BY ... DESC, then keep the first rows with LIMIT.
Show the solution
solution.sql
Run this code
SELECT name, salary
FROM employees
ORDER BY salary DESC
LIMIT 3;
Why it works
ORDER BY salary DESC sorts from the highest salary down, and LIMIT 3 keeps the first three rows of that sorted list. Without ORDER BY, LIMIT would return three rows in no guaranteed order.
Common mistake
Forgetting DESC sorts from the lowest salary, so LIMIT 3 returns the three lowest-paid employees.