SELECT with LIMIT
Return the top 3 highest-paid employees.
- Sorting
- Top-N
Exercise brief
Understand the request
Compensation committee The review pack only needs the top three earners.
Return only the top 3 highest-paid employees — first_name, last_name, salary — sorted from highest to lowest. (Hint: combine ORDER BY with a row-limiting clause.)
Return
- Return first_name, last_name, and salary.
Constraints
- Order by salary descending.
- Limit the result to 3 rows.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
first_nameVARCHAR(50)last_nameVARCHAR(50)salaryINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
You need two things at once: ordering (so the highest salary is first) and a row cap (so only the first 3 are returned).
Hint 2
In SQLite/PostgreSQL/MySQL: `ORDER BY salary DESC LIMIT 3`. In SQL Server: `SELECT TOP 3 …`. In Oracle 12c+: `FETCH FIRST 3 ROWS ONLY`.
Hint 3
Sort salaries from highest to lowest first, then apply the selected engine's three-row limit.
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 FROM employees ORDER BY salary DESC LIMIT 3;Why this works
LIMIT (and its dialect cousins TOP and FETCH FIRST) caps the result set. It must be paired with ORDER BY to be deterministic — without ORDER BY, "top 3" could be any 3 rows. The engines differ here: this question keeps a portable solution per engine via `solutionsByEngine`.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| first_name | last_name | salary |
|---|---|---|
| John | Smith | 120000 |
| Emma | Taylor | 95000 |
| Grace | White | 90000 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
WHERE Clause & Filtering
Practice SQL WHERE clauses with realistic boundary, NULL, text, date, exclusion, and production-filtering problems.
Basic SQL Functions
Practice production-oriented string cleanup, numeric transformations, NULL handling, tolerant conversion, and delimiter parsing.
ORDER BY & Sorting
Practice deterministic SQL ordering with tie-breakers, custom priorities, NULL placement, expressions, joined data, aggregates, and portable top-N patterns.
Open the interactive workspace and practice across SQL topics.