Easy SELECT basics Employees database

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

Press Run to see your query's result, or Check answer to compare it with the expected result.

Expected result

namesalary
Priya Nair9200
Tom Becker8800
Mei Chen7600

The row order matters for this question.

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.

Want to try the query on MySQL or PostgreSQL? Open it in the SQL Online Compiler or SQLite Online.