Last updated
SQL ORDER BY
Definition: ORDER BY sorts the result by one or more columns — ascending (ASC, the default) or descending (DESC).
Example 1 — cheapest products first
SELECT ProductName, Price FROM Products ORDER BY Price;
Example 2 — most expensive first
SELECT ProductName, Price FROM Products ORDER BY Price DESC;
Example 3 — sort by text (A to Z)
SELECT CustomerName FROM Customers ORDER BY CustomerName ASC;
Example 4 — sort by two columns
SELECT * FROM Customers ORDER BY Country, Age DESC;
This sorts by country first, then by age (oldest first) within each country.
💡 Tip: ORDER BY comes after WHERE when you use both.
Try it Yourself
Output
Ad · responsive