Skip to content

OFFSET

Medium — good to knowDatabase

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.