Lesson 6 of 9
ORDER BY & LIMIT
ORDER BY sorts results. Use ASC for ascending (A-Z, 0-9) or DESC for descending. LIMIT restricts how many rows are returned.
SQL
-- Sort by price lowest to highest
SELECT * FROM products ORDER BY price ASC;
-- Sort by newest first
SELECT * FROM orders ORDER BY created_at DESC;
-- Get top 5 most expensive
SELECT * FROM products ORDER BY price DESC LIMIT 5;