cancel
Showing results for 
Search instead for 
Did you mean: 

A very newbie question: how does "LIMIT" in Cypher limit results?

yuxin
Node

Hello, everyone, 

I am wondering of the "limit" clause in cypher and I searched its documentation but have not found an explanation yet. How does the "Limit" limit nodes, based on what criteria?

e.g. if I run

match (n) return n limit 10

then 10 nodes will be returned, but why these 10 not other 10? Are they selected based on index or what? I first thought they were randomly picked, but if I rerun the code, the result is the same. Therefore, I this the clause must select the nodes based on certain criteria.

 

I would appreciate for any explanation and hint. Thanks and Best

1 ACCEPTED SOLUTION

giuseppe_villan
Graph Fellow

@yuxin 

The criteria with which neo4j obtains the result are the internal ids of the nodes and relationships.


In fact, if you create a new database with for example 100 nodes and 50 relationships,
executing a  "match (n) return id(n) limit 5"   or a "match ()-[r]->() return id(r) limit 5",

the results will always be `0,1,2,3,4`

View solution in original post

2 REPLIES 2

giuseppe_villan
Graph Fellow

@yuxin 

The criteria with which neo4j obtains the result are the internal ids of the nodes and relationships.


In fact, if you create a new database with for example 100 nodes and 50 relationships,
executing a  "match (n) return id(n) limit 5"   or a "match ()-[r]->() return id(r) limit 5",

the results will always be `0,1,2,3,4`

Thanks for the explanation! It is clear now 🙂

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.