SQL ORDER BY
Sort results in ascending or descending order.
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.
Show the highest supplier prices first or list the oldest open orders at the top of a review.
The pattern
SELECT columns
FROM table
ORDER BY column DESC;Example
SELECT ProductName, Price
FROM Products
ORDER BY Price DESC
LIMIT 3;Run the example
Edit the query and run it against the built-in demo tables. Nothing is sent to a server.
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.
Which keyword sorts highest to lowest?
Progress is stored only in this browser. No account required.