SELECT with ORDER BY
Return employees ordered by salary descending.
- Sorting
Exercise brief
Understand the request
HR business partner Leadership wants the employee pay list sorted from highest to lowest salary.
Display first_name, last_name, and salary for every employee, sorted from highest salary to lowest.
Return
- Return first_name, last_name, and salary.
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_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
ORDER BY belongs at the end of the query. Use DESC for descending order, ASC (or no keyword) for ascending.
Hint 2
Syntax: SELECT … FROM … ORDER BY <column> DESC;
Hint 3
Finish the query with an ORDER BY clause that puts the largest salary first.
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;Why this works
ORDER BY runs after WHERE and SELECT but before the result is returned. The default direction is ascending; add DESC for largest-first. The expected answer has all 10 employees, sorted from John ($120k) down to Henry ($55k).
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 |
| Alice | Johnson | 85000 |
| Bob | Wilson | 80000 |
| David | Brown | 70000 |
| Ivy | Martinez | 68000 |
| Frank | Green | 65000 |
| Carol | Davis | 60000 |
| Henry | Clark | 55000 |
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.