Loading…
The ORDER BY clause sorts your results in a specific order. Without it, SQL returns rows in no guaranteed order!
SELECT columns FROM table_name
ORDER BY column_name;
By default, results are sorted in ascending order:
-- Sort by price (cheapest first)
SELECT * FROM products ORDER BY price;-- Sort alphabetically by name
SELECT * FROM products ORDER BY name;
-- Sort by category
SELECT * FROM products ORDER BY category;
Sorting helps you:
ORDER BY always comes near the end of the query, after WHERE (if present).
Select all products and order them by price (lowest to highest).
Downloading SQL engine… (one-time)
This runs entirely in your browser and is cached for next time.