LIMIT 1 for the Single Latest Row
Return the single highest-paid employee.
- CTEs
- Sorting
- Top-N
Interview brief
Understand the request
Executive reporting analyst The single-record executive summary card shows only the highest-paid employee.
Return the most recently hired employee. If two rows tie on hire_date, prefer the larger employee_id. Show first_name, last_name, hire_date, employee_id.
Return
- Return first_name, last_name, and salary.
Constraints
- Use LIMIT 1 with ORDER BY salary DESC.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
first_nameTEXTlast_nameTEXThire_dateDATEemployee_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
LIMIT 1 + ORDER BY <metric> DESC = "the row with the maximum metric". Use ASC for "the row with the minimum".
Hint 2
Without a tie-breaker, "the most recent" becomes whichever tied row the engine happens to return first.
Hint 3
ORDER BY hire_date DESC, employee_id DESC LIMIT 1
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT first_name, last_name, hire_date, employee_id FROM employees ORDER BY hire_date DESC, employee_id DESC LIMIT 1;Why this works
LIMIT 1 is a clean way to get a single extreme value. The window-function alternative (`ROW_NUMBER() OVER (ORDER BY ...)`) is more flexible — it can return the per-group extreme without correlated subqueries.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| first_name | last_name | hire_date | employee_id |
|---|---|---|---|
| Emma | Thomas | 2023-01-10 | 10 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics: