Limits the number of returned results.
LIMIT <count>
## Overview LIMIT constrains the number of rows returned by a query or passed downstream in a WITH clause. It is one of the most commonly used clauses for controlling output size, and it works in combination with ORDER BY and SKIP to implement sorting and pagination patterns. In DeltaForge, LIMIT is evaluated after ORDER BY and SKIP in the execution pipeline. The engine computes and sorts all qualifying rows before truncating the result to the requested count. ## Behavior - LIMIT N returns at most N rows. If the result set contains fewer than N rows, all rows are returned. - LIMIT 0 produces an empty result set. - When combined with ORDER BY, LIMIT retains the first N rows in sorted order. Without ORDER BY, the set of rows returned is non-deterministic. - When combined with SKIP, the evaluation order is: sort (ORDER BY), discard (SKIP), then truncate (LIMIT). - Inside a WITH clause, LIMIT operates on the intermediate result before subsequent MATCH or RETURN clauses consume it. ## Limitations - LIMIT does not eliminate the cost of computing and sorting all rows that precede it in the pipeline. A query that matches millions of nodes but applies LIMIT 10 still traverses and sorts the full result before truncation. - LIMIT does not support parameter expressions in all contexts. Use integer literals for maximum compatibility.
| Name | Type | Description |
|---|---|---|
count | Specifies the maximum number of rows to include in the result set. Must be a non-negative integer literal or expression. A value of 0 returns an empty result. |
-- Return up to 10 person nodes
USE my_zone.my_schema.my_graph
MATCH (n:Person)
RETURN n.name AS name
LIMIT 10;
-- Top 5 employees by salary
USE my_zone.my_schema.my_graph
MATCH (e:Employee)
RETURN e.name AS name, e.salary AS salary
ORDER BY e.salary DESC
LIMIT 5;
-- Pagination: page 3 of size 10
USE my_zone.my_schema.my_graph
MATCH (n:Employee)
RETURN n.name AS name, n.department AS dept
ORDER BY n.name
SKIP 20
LIMIT 10;
-- Limit inside WITH for intermediate result reduction
USE my_zone.my_schema.my_graph
MATCH (a:Author)-[:WROTE]->(p:Paper)
WITH a, count(p) AS papers ORDER BY papers DESC LIMIT 3
MATCH (a)-[:AFFILIATED_WITH]->(o:Organization)
RETURN a.name AS author, papers, o.name AS org;