How to Limit Rows in MySQL
Last updated July 25, 2026 · By the SaturnSQL team
LIMIT n returns at most n rows; LIMIT n OFFSET m skips m rows first, which is the classic pagination pattern. Always pair LIMIT with ORDER BY, otherwise which rows you get is not deterministic.
SELECT * FROM orders ORDER BY created_at DESC LIMIT 10;Offset pagination
SELECT * FROM orders
ORDER BY id
LIMIT 20 OFFSET 40;Keyset pagination for deep pages
OFFSET still scans and discards all skipped rows, so page 5000 is slow. Filtering on the last seen key stays fast at any depth.
SELECT * FROM orders
WHERE id > 1040
ORDER BY id
LIMIT 20;Run this in SaturnSQL
SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.
Try it free