LIMIT and OFFSET
Fetch the first N rows and paginate.
Fetching Just a Few Rows
Sometimes you don't want every matching row, just the first handful. LIMIT caps how many rows the query returns.
This returns at most 5 products.
SELECT name, price
FROM products
LIMIT 5;LIMIT Without ORDER BY Is Random
LIMIT on its own gives you some rows, but which rows is undefined. Always pair it with ORDER BY so the result is meaningful and repeatable.
-- The 5 newest orders, deterministically
SELECT id, total, created_at
FROM orders
ORDER BY created_at DESC
LIMIT 5;