LIMIT
Introduction
LIMIT
accepts any expression that evaluates to a positive integer — however the expression cannot refer to nodes or relationships.
Graph
N0 [ label = "name = \'A\'\l" ] N0 -> N4 [ color = "#2e3436" fontcolor = "#2e3436" label = "KNOWS\n" ] N0 -> N3 [ color = "#2e3436" fontcolor = "#2e3436" label = "KNOWS\n" ] N0 -> N2 [ color = "#2e3436" fontcolor = "#2e3436" label = "KNOWS\n" ] N0 -> N1 [ color = "#2e3436" fontcolor = "#2e3436" label = "KNOWS\n" ] N1 [ label = "name = \'B\'\l" ] N2 [ label = "name = \'C\'\l" ] N3 [ label = "name = \'D\'\l" ] N4 [ label = "name = \'E\'\l" ]
Return a subset of the rows
To return a subset of the result, starting from the top, use this syntax:
Query
MATCH (n)
RETURN n.name
ORDER BY n.name
LIMIT 3
The top three items are returned by the example query.
n.name |
---|
|
|
|
3 rows |
Using an expression with LIMIT
to return a subset of the rows
Limit accepts any expression that evaluates to a positive integer as long as it is not referring to any external variables:
Query
MATCH (n)
RETURN n.name
ORDER BY n.name
LIMIT toInteger(3 * rand())+ 1
Returns one to three top items.
n.name |
---|
|
|
|
3 rows |