OFFSET
ELI5 — The Vibe Check
OFFSET skips a number of rows before starting to return results. Combined with LIMIT, it is how you do pagination: page 2 = skip the first 20 (OFFSET 20), then take 20 more (LIMIT 20).
Real Talk
OFFSET skips a specified number of rows before beginning to return rows from the query. Combined with LIMIT, it implements page-based pagination. However, large OFFSETs are inefficient because the database must still scan and discard the skipped rows. Cursor-based pagination is more efficient for large datasets.
Show Me The Code
-- Page 3: skip 40, take 20
SELECT * FROM posts
ORDER BY created_at DESC
LIMIT 20 OFFSET 40;
When You'll Hear This
"Use OFFSET for pagination: LIMIT 10 OFFSET 20 gets page 3." / "High OFFSET values hurt performance — consider cursor-based pagination instead."
Related Terms
LIMIT
LIMIT caps how many rows a query returns. If your users table has 1 million rows, you do not want to load all of them at once.
ORDER BY
ORDER BY sorts your query results. Add DESC for newest first, ASC for oldest first.
SELECT
SELECT is how you ask a database to give you data. It is the 'Read' in CRUD.