Documentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
LIMIT clause
TheLIMIT clause controls how many rows are returned from your query results.
Basic syntax
Select first rows:m rows from the result, or all records when there are fewer than m.
Alternative TOP syntax (MS SQL Server compatible):
LIMIT m and can be used for compatibility with Microsoft SQL Server queries.
Select with offset:
n rows, then returns the next m rows.
In both forms, n and m must be non-negative integers.
Negative limits
Select rows from the end of the result set using negative values:| Syntax | Result |
|---|---|
LIMIT -m | Last m rows |
LIMIT -m OFFSET -n | Last m rows after skipping the last n rows |
LIMIT m OFFSET -n | First m rows after skipping the last n rows |
LIMIT -m OFFSET n | Last m rows after skipping the first n rows |
LIMIT -n, -m syntax is equivalent to LIMIT -m OFFSET -n.
Fractional limits
Use decimal values between 0 and 1 to select a percentage of rows:| Syntax | Result |
|---|---|
LIMIT 0.1 | First 10% of rows |
LIMIT 1 OFFSET 0.5 | The median row |
LIMIT 0.25 OFFSET 0.5 | Third quartile (25% of rows after skipping the first 50%) |
- Fractions must be Float64 values greater than 0 and less than 1.
- Fractional row counts are rounded to the next whole number.
Combining limit types
You can mix standard integers with fractional or negative offsets:LIMIT … WITH TIES
TheWITH TIES modifier includes additional rows that have the same ORDER BY values as the last row in your limit.
WITH TIES, all rows matching the last value are included:
2) as row 5.
The same applies when the offset is specified with the OFFSET keyword:
1, 1, 2, but the second 2 is included because it ties with the last row.
WITH TIES is not supported with negative limits.ORDER BY ... WITH FILL modifier.
Considerations
Non-deterministic results: Without anORDER BY clause, the rows returned may be arbitrary and vary between query executions.
Server-side limit: The number of rows returned can also be affected by the limit setting.
See also
- LIMIT BY — Limits rows per group of values, useful for getting top N results within each category.