OFFSET is an optional clause used with ORDER BY and usually LIMIT or FETCH to implement pagination. After the result set is ordered, the database discards the first N rows defined by OFFSET and returns the remaining rows (or the next M rows when combined with LIMIT/FETCH). OFFSET is evaluated after WHERE, GROUP BY, HAVING, and ORDER BY, so the skipped rows are determined from the final sorted list. Because the database must still compute and sort all preceding rows, large OFFSET values can hurt performance. Use keyset pagination as an alternative when working with very large tables. In SQL Server, Oracle, and ANSI SQL, OFFSET pairs with FETCH NEXT; in PostgreSQL, MySQL, and SQLite it pairs with LIMIT.
OFFSET INT
- Required. Number of rows to skip before returning data.LIMIT / FETCH INT
- Optional but common companion clause that caps how many rows are returned after the offset.LIMIT, FETCH NEXT, ORDER BY, TOP, ROW_NUMBER, keyset pagination
SQL:2008 (OFFSET/FETCH), earlier vendor implementations in PostgreSQL 7.0
LIMIT caps how many rows are returned. OFFSET skips rows before the cap is applied. Together they define a page: OFFSET 20 LIMIT 10 returns rows 21-30.
Technically yes, but the returned rows are unpredictable because relational tables are unordered. Always pair OFFSET with a deterministic ORDER BY.
Use keyset (cursor) pagination: filter on the last seen sort key (e.g., WHERE id > last_id) instead of OFFSET. This lets the database leverage indexes.
OFFSET counts from zero in all major SQL dialects. OFFSET 0 returns the result set starting from the first row.