SQL pagination

SQL pagination splits a large result into pages with LIMIT and OFFSET. The offset is computed as (page - 1) * size. A stable ORDER BY is needed for a consistent order, and a COUNT to know the total number of pages. A high OFFSET becomes slow.

Example

SELECT * FROM produits ORDER BY id LIMIT 20 OFFSET 40;

Related concepts

The whole glossary