LearnSQLSQL ORDER BY
SORTING

SQL ORDER BY

Sort results in ascending or descending order.

After this lessonRank high values first and combine sorting with LIMIT.

How it works

ORDER BY controls the presentation order of the result. ASC is the default; DESC reverses the order.

You can sort by more than one column. This is useful when several rows share the same primary sorting value and you need a stable secondary order.

REAL WORK

Show the highest supplier prices first or list the oldest open orders at the top of a review.

SYNTAX

The pattern

SELECT columns
FROM table
ORDER BY column DESC;

Example

SELECT ProductName, Price
FROM Products
ORDER BY Price DESC
LIMIT 3;
TRY IT

Run the example

Edit the query and run it against the built-in demo tables. Nothing is sent to a server.

SQL playground

The learning runner supports SELECT, WHERE, LIKE, IN, BETWEEN, GROUP BY, HAVING, JOIN, aggregates, ORDER BY and LIMIT. Advanced lessons explain additional production SQL concepts even when the mini runner does not execute that syntax.

QUICK CHECK

Which keyword sorts highest to lowest?

Progress is stored only in this browser. No account required.