Bottom N — Lowest Values with ORDER BY ASC + LIMIT
List the 3 LOWEST-paid employees with a deterministic tie-breaker. Show first_name, last_name, salary, employee_id.
- CTEs
- Sorting
- Top-N
Interview brief
Understand the request
List the 3 LOWEST-paid employees with a deterministic tie-breaker. Show first_name, last_name, salary, employee_id.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
first_nameTEXTlast_nameTEXTsalaryDECIMALemployee_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
For Bottom-N use ASC (default) instead of DESC. The structure is otherwise identical to Top-N.
Hint 2
Don't try to compute Bottom-N by sorting DESC and reversing — sorting ASC + LIMIT is simpler and lets the engine optimise (it can stop reading after N rows in some cases).
Hint 3
ORDER BY salary, employee_id LIMIT 3
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT first_name, last_name, salary, employee_id FROM employees ORDER BY salary, employee_id LIMIT 3;Why this works
Bottom-N gets the same engine optimisations as Top-N (the planner can use a 'top-N sort' that keeps only N rows in memory). Reversing a DESC sort wastes memory and CPU.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| first_name | last_name | salary | employee_id |
|---|---|---|---|
| Emma | Thomas | 52000 | 10 |
| Jane | Smith | 55000 | 2 |
| Nicole | Rodriguez | 56000 | 14 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics: