OFFSET in MySQL — How It Works

What the MySQL OFFSET function does, with an example.

Published October 22, 2026

OFFSET n skips the first n rows before LIMIT counts rows: LIMIT 10 OFFSET 20 returns rows 21–30.

How it works

Large offsets scan and discard rows, so deep pages get slow.

Try it in MySQL

SELECT * FROM posts ORDER BY id LIMIT 10 OFFSET 20
rows 21–30
SELECT * FROM posts ORDER BY id LIMIT 20, 10
same, older syntax
SELECT * FROM posts WHERE id > 120 ORDER BY id LIMIT 10
keyset alternative

Practical examples

Example 1

SELECT * FROM posts ORDER BY id LIMIT 10 OFFSET 20;
-- rows 21–30

Example 2

SELECT * FROM posts ORDER BY id LIMIT 20, 10;
-- same, older syntax

Example 3

SELECT * FROM posts WHERE id > 120 ORDER BY id LIMIT 10;
-- keyset alternative

Use it in a real query

SELECT * FROM posts ORDER BY id LIMIT 10 OFFSET 20;

Common mistakes

  • OFFSET without ORDER BY.
  • Huge offsets on large tables.
  • Pages shifting when rows are inserted.

Key takeaways

  • OFFSET in one line: OFFSET n skips the first n rows before LIMIT counts rows: LIMIT 10 OFFSET 20 returns rows 21–30.
  • Try queries in a test database first.
  • Check NULL handling and data types.

FAQ

Alternative to OFFSET?

Keyset (seek) pagination.

Does OFFSET work in other databases?

Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.

More SQL articles