Skip to content
Developer Edition runs on one host and does not require a product license file. Need multi-host deployment or performance testing at scale? Explore Enterprise Edition

LIMIT clause

The LIMIT clause specifies the maximum number of rows to return.

Syntax

limit_clause
LIMIT number_of_rows

limit_clause ::=
    'LIMIT' number_of_rows

Parameters

number_of_rows

A non-negative integer indicating the upper bound of the number of rows to be returned. If this bound is greater than or equal to the total number of rows, all rows are returned. Otherwise, the number of rows returned is no larger than this bound.

Examples

Limit with a number smaller than the total number of rows

'''
TABLE users TYPED TABLE {id INT, name STRING} =
    (199, "Julie Kavner"),
    (198, "Tom Cruise"),
    (197, "Amy Hasegawa")
FOR r IN users
RETURN r.id AS id, r.name AS name
LIMIT 2
'''

The preceding statement returns only the first 2 rows.

Return:

+-----+--------------+
| id  | name         |
+-----+--------------+
| 199 | Julie Kavner |
| 198 | Tom Cruise   |
+-----+--------------+

Limit with a number exceeding the total number of rows

If the limit exceeds the total number of rows, all rows are returned.

'''
TABLE users TYPED TABLE {id INT, name STRING} =
    (199, "Julie Kavner"),
    (198, "Tom Cruise"),
    (197, "Amy Hasegawa")
FOR r IN users
RETURN r.id AS id, r.name AS name
LIMIT 100
'''

Return:

+-----+--------------+
| id  | name         |
+-----+--------------+
| 199 | Julie Kavner |
| 198 | Tom Cruise   |
| 197 | Amy Hasegawa |
+-----+--------------+