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

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_namelast_namesalary
JohnSmith120000
EmmaTaylor95000
GraceWhite90000
AliceJohnson85000
BobWilson80000
DavidBrown70000
IvyMartinez68000
FrankGreen65000
CarolDavis60000
HenryClark55000

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.