3.3.18. LIMIT

LIMIT constrains the number of rows in the output.

LIMIT accepts any expression that evaluates to a positive integer — however the expression cannot refer to nodes or relationships.

Figure 3.13. Graph
alt

3.3.18.1. Return first part

To return a subset of the result, starting from the top, use this syntax:

Query. 

MATCH (n)
RETURN n
ORDER BY n.name
LIMIT 3

The top three items are returned by the example query.

Result. 

+-------------------+
| n                 |
+-------------------+
| Node[0]{name:"A"} |
| Node[1]{name:"B"} |
| Node[2]{name:"C"} |
+-------------------+
3 rows

3.3.18.2. Return first from expression

Limit accepts any expression that evaluates to a positive integer as long as it is not referring to any external variables:

Parameters. 

{
  "p" : 12
}

Query. 

MATCH (n)
RETURN n
ORDER BY n.name
LIMIT toInt(3 * rand())+ 1

Returns one to three top items

Result. 

+-------------------+
| n                 |
+-------------------+
| Node[0]{name:"A"} |
| Node[1]{name:"B"} |
+-------------------+
2 rows