ORDER BY & LIMIT: Top 3 Highest-Paid Employees

Basics
BasicsORDER BYLIMITGoogleAmazonMeta

Table

  • employees(emp_id INT, name VARCHAR, salary INT)

Task

From employees(emp_id, name, salary), return emp_id, name, salary for the top 3 highest-paid employees (break ties by emp_id ASC).

Why It Matters: ORDER BY ... DESC LIMIT K powers leaderboards, top-earner reports, and recent-activity feeds in every analytics SQL interview.

Output columns: emp_id, name, salary

Example

Input — employees

emp_idnamesalary
1A90
2B140
3C120
4D140
5E80

Expected Output

emp_idnamesalary
2B140
4D140
3C120

Explanation: Sorts rows by salary descending (with deterministic tie-break) and returns only the top 3 rows.

Requirements

  • Exact output columns: emp_id, name, salary
  • Row order: Exact ORDER BY order is checked by the grader.
  • Query type: Write a single read-only Standard SQL SELECT (or WITH ... SELECT) query.

Constraints & Evaluation Criteria

  • Return `emp_id, name, salary` for the top 3 earners.

Hints

SQL
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
employees (5 rows)
Expected Output / Criteria
3 row(s): (2, B, 140); (4, D, 140); (3, C, 120)