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_id | name | salary |
|---|---|---|
| 1 | A | 90 |
| 2 | B | 140 |
| 3 | C | 120 |
| 4 | D | 140 |
| 5 | E | 80 |
Expected Output
| emp_id | name | salary |
|---|---|---|
| 2 | B | 140 |
| 4 | D | 140 |
| 3 | C | 120 |
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 BYorder is checked by the grader. - Query type: Write a single read-only Standard SQL
SELECT(orWITH ... SELECT) query.
Constraints & Evaluation Criteria
- Return `emp_id, name, salary` for the top 3 earners.
Hints
SQL⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
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)