SQL Pagination Across Databases: LIMIT, TOP, and OFFSET-FETCH Compared
By Sharon Ben-Moshe · August 2, 2026 · 2 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
PostgreSQL, MySQL, and SQLite page results with LIMIT. SQL Server uses TOP or OFFSET-FETCH. BigQuery uses standard LIMIT/OFFSET. Here's how the syntax — and the gotchas — differ.
Quick answer
PostgreSQL, MySQL, SQLite, and BigQuery all paginate with LIMIT n OFFSET m. SQL Server instead uses either SELECT TOP(n) or, for true offset-based paging, OFFSET m ROWS FETCH NEXT n ROWS ONLY — and that clause requires an ORDER BY, unlike LIMIT elsewhere.
FAQs
Does SQL Server support LIMIT?
No. SQL Server has no LIMIT keyword — use TOP(n) for a simple row cap, or OFFSET ... FETCH NEXT ... ROWS ONLY for offset-based pagination.
Why does my MySQL LIMIT return the wrong rows?
Check the argument order. MySQL uniquely supports LIMIT offset, count as well as LIMIT count — mixing them up silently returns a different page than intended, with no error.
Does OFFSET/FETCH need ORDER BY in SQL Server?
Yes, it's mandatory — SQL Server raises a syntax error if OFFSET ... FETCH NEXT is used without a preceding ORDER BY.
Is pagination deterministic without ORDER BY?
No, in any of these five dialects. Without an ORDER BY on a unique or near-unique column, the database can return rows in a different order between two otherwise-identical paged requests.
Does BigQuery support OFFSET?
Yes — BigQuery uses the same LIMIT n OFFSET m syntax as PostgreSQL, MySQL, and SQLite.
Keep reading
SQL UPSERT Across Dialects: ON CONFLICT, ON DUPLICATE KEY, and MERGE
By Sharon Ben-Moshe · Aug 8, 2026
Every major SQL dialect can insert-or-update in one statement, but the syntax is different everywhere — ON CONFLICT, ON DUPLICATE KEY UPDATE, INSERT OR REPLACE, and MERGE all solve the same problem in incompatible ways.
Read postSQL Date and Time Functions Across Dialects
By Sharon Ben-Moshe · Aug 8, 2026
“Add 7 days” is DATEADD in SQL Server, DATE_ADD in MySQL and BigQuery, a raw interval in PostgreSQL, and a modifier string in SQLite — the same operation, four unrelated shapes. Here's the working syntax for each dialect's core date functions.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.