ORDER BY sorts results by one or more columns.
ASC: ascending (the default), A→Z, 0→9.DESC: descending.- Several columns:
ORDER BY Country, CustomerNamesorts by country, then by name within each country.
Sort the result set.
✍️ 3 exercises + code challenge in this lessonORDER BY sorts results by one or more columns.
ASC: ascending (the default), A→Z, 0→9.DESC: descending.ORDER BY Country, CustomerName sorts by country, then by name within each country.Mastering SQL ORDER BY helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
SELECT ProductName, Price FROM Products
ORDER BY Price DESC;
SELECT CustomerName, Country, City FROM Customers
ORDER BY Country ASC, City DESC;
Check what you learned in “SQL ORDER BY”.
Sort from highest to lowest price.
SELECT * FROM Products ORDER BY Price ;
What is the default sort direction?
Select CustomerName from Customers sorted by CustomerName A to Z.
Free sign-in required · Google login available
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services