Thuta Learning
BasicData & Databasesbeginner

ORDER BY

Relax. We'll talk through this in plain words — no textbook voice.

ORDER BY is used to sort your results in order. It's a must-know keyword for reports, leaderboards, latest posts, and sorting products by price.

ASC — smallest to largest / A to Z

DESC — largest to smallest / Z to A

Default is ASC.

sql
SELECT CustomerName, Country
FROM Customers
ORDER BY Country ASC, CustomerName ASC;
You should see
+--------------------+---------+ | CustomerName | Country | +--------------------+---------+ | Alfreds Futterkiste| Germany | | Ana Trujillo | Mexico | | Antonio Moreno | Mexico | | Around the Horn | UK | +--------------------+---------+ Important things to notice: It sorts by Country first, and when the country is the same, it sorts further by CustomerName. Practical use: You could write ORDER BY created_at DESC on blog posts to show the newest ones first.
ORDER BY | Thuta Learning