Skip to main content

How do you sort data in descending order?

To sort data in descending order, use the ORDER BY operator with the DESC (descending) keyword. This is the opposite of ascending order: larger values come first, then smaller ones.

Example

sql
SELECT name, salary FROM employees ORDER BY salary DESC;

SQL returns employees starting with the highest salary and ending with the lowest.

How it works

  • For numbers, from larger to smaller (5000, 2000, 1000).
  • For dates, from later to earlier (2025-10-21 -> 2025-01-01).
  • For text, in reverse alphabetical order (Z, Y, X...).

You can sort by several columns

sql
SELECT name, department, salary FROM employees ORDER BY department ASC, salary DESC;

Sorts by department first (alphabetically), then within each department, by salary from largest to smallest.

Summary: ORDER BY ... DESC is a way to output data from the largest to the smallest. It's used for rankings, top lists, most-recent dates, and any "largest" values.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

How do you sort data in descending order?: SQL Interview Question