본문 바로가기

DKE/Neo4j

[Neo4j] LIMIT / 2023.02.16

https://neo4j.com/docs/cypher-manual/current/clauses/limit/

 

LIMIT - Cypher Manual

`LIMIT` constrains the number of returned rows.

neo4j.com

*Example Graph

create 
(a {name:'A'}),
(b {name:'B'}),
(c {name:'C'}),
(d {name:'D'}),
(e {name:'E'}),
(a)-[:KNOWS]->(b),
(a)-[:KNOWS]->(c),
(a)-[:KNOWS]->(d),
(a)-[:KNOWS]->(e)

LIMIT는 반환되는 행의 수를 제한함
LIMIT는 양의 정수로 평가되는 모든 식을 허용하지만 노드나 관계를 참조할 수는 없음

 

1. Return a limited subset of the rows

#반환되는 행을 3개로 제한
MATCH (n)
RETURN n.name
ORDER BY n.name
LIMIT 3

2. Using an expression with LIMIT to return a subset of the rows

#행 1에 랜덤하게 0, 1 또는 2를 더한 값을 제한함
#따라서 임의로 1, 2 또는 3 행으로 제한
MATCH (n)
RETURN n.name
ORDER BY n.name
LIMIT 1 + toInteger(3 * rand())

3. LIMIT will not stop side effects (skip)

 

'DKE > Neo4j' 카테고리의 다른 글

[Neo4j] SKIP / 2023.02.15  (0) 2023.02.15
[Neo4j] ORDER BY / 2023.02.14  (0) 2023.02.14
[Neo4j] UNWIND / 2023.02.13  (0) 2023.02.13
[Neo4j] WITH / 2023.02.13  (0) 2023.02.13
[Neo4j] RETURN / 2023.02.08  (0) 2023.02.08