LIMIT, FETCH, and OFFSET Clauses
The LIMIT
clause specifies the maximum number of rows to return. <count>
specifies the maximum number of rows to return. The LIMIT
clause consists of two independent subclauses, LIMIT { <count> | ALL }
and OFFSET <start>
. <start>
specifies the number of rows to skip before starting to return rows.
If you use LIMIT
, use an ORDER BY
that uniquely orders results. Without ORDER BY
, you get a random subset of the query’s rows.
If the <count>
expression evaluates to NULL, it’s treated as LIMIT ALL
. If <start>
evaluates to NULL, it’s treated the same as OFFSET 0
.
An alternative to LIMIT
and OFFSET
is FETCH
and OFFSET
.
In this syntax, the <start>
or <count>
value is a literal constant, a parameter, or a variable name. The default <count>
is 1. The WITH TIES
option returns rows that tie for the last place in the result set.