Descending Order
To sort from the largest value to the smallest, write DESC after the column. It's short for descending:
SELECT title, released
FROM games
ORDER BY released DESC;| title | released |
|---|---|
| Knight's Oath | 2025-11-14 |
| Goal Rush | 2025-09-26 |
| Turbo Karts | 2025-06-05 |
| Star Pilots | 2025-01-23 |
| … | … |
Now the newest games come first. Descending order turns everything around: the largest numbers first, text from Z to A, the latest dates first, and the rows with NULL at the very end. Here, those are Robot Rebellion and Mystery Manor, which haven't come out yet.
The opposite of DESC is ASC, ascending. It's the default, so ORDER BY released ASC is the same as ORDER BY released. You don't have to write it, but sometimes it makes a query clearer: whoever reads it sees that you wanted ascending order on purpose.
DESC comes in handy whenever you want “the most” of something at the top: the most expensive games, the newest orders, the best reviews. In the next exercises, you'll combine it with sorting by several columns and with showing just the first few rows.
Typical mistake: DESC in front of the column. It belongs after the column it sorts, so this query ends with an error:
SELECT title, price
FROM games
ORDER BY DESC price;Error on line 1: near "price": syntax errorInstructions
The query in the editor sorts the games from the cheapest. Change it, so that the most expensive games come first:
| title | price |
|---|---|
| Knight's Oath | 60 |
| Goal Rush | 50 |
| Ice Hockey Pro | 45 |
| … | … |
Below it, add a query that shows the name of every customer and the day they joined (joined), with the customers who joined last at the top:
| name | joined |
|---|---|
| Max Baker | 2025-10-03 |
| Sophie Adams | 2025-08-21 |
| Henry Scott | 2025-05-06 |
| … | … |
Start programming for free
2/9