SELECT Statements SQL Topic exerciseEasyVerified answerSQLite + PostgreSQL + MySQL + SQL Server live · 1 guided

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_namelast_namesalary
JohnSmith120000
EmmaTaylor95000
GraceWhite90000

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Practice Online

Open the interactive workspace and practice across SQL topics.