-
Notifications
You must be signed in to change notification settings - Fork 410
LIMIT clause
Daniël van Eeden edited this page Mar 13, 2024
·
9 revisions
SQL standard does not define a LIMIT or OFFSET clause.
Every dialect however supports either LIMIT OFFSET
or OFFSET FETCH
syntax.
LIMIT count [OFFSET offset]
DB2:1
LIMIT count [OFFSET offset]
LIMIT offset, count
[OFFSET count {ROW | ROWS}]
[FETCH NEXT count {ROW | ROWS} ONLY]
DB2i:1
LIMIT count [OFFSET offset]
LIMIT offset, count
[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]
[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 }]
[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]
LIMIT {count | ALL}
SQLite supports two forms:
LIMIT [offset ","] count
LIMIT count OFFSET offset
TiDB supports two forms:
LIMIT [offset ","] count
LIMIT count OFFSET offset
[FETCH { FIRST | NEXT } [count] { ROW | ROWS } ONLY]
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}
Notes:
- DB2 and DB2i syntax diagrams don't mention the LIMIT clause, but it is mentioned at the bottom of the page as an alternative supported syntax.