Rank Salaries from Highest to Lowest
Return first_name, last_name, salary, and department_id for every employee, ordered by salary descending.
- Sorting
Exercise brief
Understand the request
Compensation partner Leaders need the same salary population ranked with the highest salary first.
List employees sorted by salary in descending order (highest first). Show first_name, last_name, salary, department_id.
Return
- Return one row per employee.
- Place the highest salary first.
Constraints
- Use ORDER BY salary DESC.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
first_nameTEXTlast_nameTEXTsalaryDECIMALdepartment_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Add the keyword DESC after the column name to reverse the order.
Hint 2
There is no DESCENDING — only DESC. ASC and DESC are the only direction keywords.
Hint 3
ORDER BY salary DESC
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, department_id FROM employees ORDER BY salary DESC;Why this works
ASC is "smallest first" for numbers, "earliest first" for dates, "alphabetical first" for text. DESC is the inverse for each. The direction keyword belongs to a single sort column — `ORDER BY a, b DESC` means a ASC, b DESC.
Success check
All employees appear exactly once from highest to lowest salary.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| first_name | last_name | salary | department_id |
|---|---|---|---|
| Mike | Johnson | 80000 | 1 |
| Amy | Taylor | 78000 | 1 |
| John | Doe | 75000 | 1 |
| Alex | Miller | 72000 | 1 |
| David | Brown | 70000 | 1 |
| Chris | Anderson | 68000 | 3 |
| Sarah | Williams | 65000 | 3 |
| Rachel | Garcia | 64000 | 3 |
| Tom | Wilson | 62000 | 3 |
| Lisa | Davis | 58000 | 2 |
Previewing 10 of 12 expected rows. Run the query in the editor to inspect the full result.
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
LIMIT & OFFSET
Practice deterministic top-N, cutoff ties, offset pagination, composite keyset cursors, and resumable bounded batches.
Ranking & NTH Value
Solve deterministic ranking, top-N, distribution, positional-frame, and rolling-window problems.
SELECT Statements
Select columns, filter rows, remove duplicates, and order query results.
Open the interactive workspace and practice across SQL topics.