LIMIT Clause
LIMIT m
allows to select the first m
rows from the result.
LIMIT n, m
allows to select the m
rows from the result after skipping the first n
rows. The LIMIT m OFFSET n
syntax is equivalent.
In the standard forms above, n
and m
are non-negative integers.
Negative limits are also supported:
LIMIT -m
selects the last m
rows from the result.
LIMIT -m OFFSET -n
selects the last m
rows after skipping the last n
rows. The LIMIT -n, -m
syntax is equivalent.
If there is no ORDER BY clause that explicitly sorts results, the choice of rows for the result may be arbitrary and non-deterministic.
LIMIT ... WITH TIES Modifier
When you set WITH TIES
modifier for LIMIT n[,m]
and specify ORDER BY expr_list
, you will get in result first n
or n,m
rows and all rows with same ORDER BY
fields values equal to row at position n
for LIMIT n
and m
for LIMIT n,m
.
Note
•WITH TIES
is currently not supported with negativeLIMIT
.
This modifier also can be combined with ORDER BY ... WITH FILL modifier.
For example, the following query
returns
but after apply WITH TIES
modifier
it returns another rows set
cause row number 6 have same value "2" for field n
as row number 5