Lesson 9 / 30
ORDER BY & LIMIT
Sort results with ORDER BY and paginate with LIMIT and OFFSET, always sorting before limiting.
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.