概述
LIMIT
语句用来限制从当前工作表返回的最多记录数。必须在LIMIT
语句中指定一个非负整数。
<limit statement> ::= "LIMIT" <non-negative integer>
示例图集
以下示例根据该图集运行:
在空图集中运行以下语句创建示例图集:
INSERT (p1:Paper {_id:'P1', title:'Efficient Graph Search', score:6, author:'Alex'}),
(p2:Paper {_id:'P2', title:'Optimizing Queries', score:9, author:'Alex'}),
(p3:Paper {_id:'P3', title:'Path Patterns', score:7, author:'Zack'}),
(p1)-[:Cites {weight:2}]->(p2),
(p2)-[:Cites {weight:1}]->(p3)
限制返回记录数
MATCH (n:Paper)
RETURN n.title LIMIT 2
结果:
n.title |
---|
Efficient Graph Search |
Optimizing Queries |
限制传出记录数
MATCH (n:Paper) LIMIT 1
MATCH p = (n)->()
RETURN p
结果:
p |
---|
(:Paper {_id: "P2", score: 9, title: "Optimizing Queries", author: "Alex"})-[:Cites {weight: 1}]->(:Paper {_id: "P3", score: 7, title: "Path Patterns", author: "Zack"}) |
限制有序记录数
MATCH (n:Paper)
ORDER BY n.title DESC
LIMIT 1
RETURN n.title
结果:
n.title |
---|
Path Patterns |