Skip to content
Rene Saarsoo edited this page Nov 12, 2023 · 9 revisions

SQL standard does not define a LIMIT or OFFSET clause.

Every dialect however supports either LIMIT OFFSET or OFFSET FETCH syntax.

BigQuery:

LIMIT count [OFFSET offset]

DB2:

[OFFSET count {ROW | ROWS}]
[FETCH NEXT count {ROW | ROWS} ONLY]

DB2i:

[OFFSET count {ROW | ROWS}]
[FETCH {FIRST | NEXT} count {ROW | ROWS} ONLY]

Hive:

LIMIT [offset ","] count

MariaDB support three forms:

LIMIT [offset ","] count

LIMIT count OFFSET offset [ROWS EXAMINED rows_limit]

[OFFSET offset { ROW | ROWS }]
[FETCH { FIRST | NEXT } [count] { ROW | ROWS } { ONLY | WITH TIES }]

MySQL supports two forms:

LIMIT [offset ","] count

LIMIT count OFFSET offset

N1QL:

[LIMIT count]
[OFFSET offset]

PL/SQL:

[OFFSET offset {ROW | ROWS}]
[FETCH { FIRST | NEXT } [count | percent PERCENT] { ROW | ROWS } { ONLY | WITH TIES }]

PostgreSQL supports two forms:

[LIMIT {count | ALL}]
[OFFSET offset]

[OFFSET offset {ROW | ROWS}]
[FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } { ONLY | WITH TIES }]

Redshift:

[LIMIT {count | ALL}]
[OFFSET offset]

SingleStoreDB supports two forms:

LIMIT [offset ","] count

LIMIT count OFFSET offset

Snowflake supports two forms:

LIMIT count [OFFSET offset]

[OFFSET offset {ROW | ROWS}]
FETCH [{FIRST | NEXT}] count [{ROW | ROWS}] [ONLY]

Spark:

LIMIT {count | ALL}

SQLite supports two forms:

LIMIT [offset ","] count

LIMIT count OFFSET offset

Transact-SQL:

In older versions the only way is to use TOP syntax:

SELECT TOP count * FROM table

Starting with SQL Server 2012, one can use the OFFSET FETCH syntax:

OFFSET offset {ROW | ROWS}
[FETCH {FIRST | NEXT} count {ROW | ROWS} ONLY]

Trino supports two forms:

[OFFSET offset [ROW | ROWS]]
LIMIT count

[OFFSET offset [ROW | ROWS]]
FETCH {FIRST | NEXT} count {ROW | ROWS} {ONLY | WITH TIES}
Clone this wiki locally