Lesson 9 / 28
ORDER BY & LIMIT
Sort results and cap how many rows come back.
Sorting rows
ORDER BY sorts ascending (ASC, default) or descending (DESC).
SELECT name, created_at FROM customers
ORDER BY created_at DESC;Limiting rows
LIMIT caps the result count — useful for pagination with OFFSET.
SELECT name FROM customers
ORDER BY name
LIMIT 2 OFFSET 1;
Output:
name Priya Nair Rahul Mehta
Always ORDER before LIMIT
Without ORDER BY, row order isn't guaranteed — always sort explicitly before using LIMIT for predictable results.