How does the LIMIT clause work?

Hi to everyone!

I am investigating the first order neighborhood of a node. The node can have an X total number of 1st order neighbors. I am limiting the query results via the LIMIT clause and I get, let's say Y neighbors. How does the LIMIT clause picks these Y neighbors out of the total population X?

I assume there is some sampling strategy running behind. If there is any resource I can get this kind of info regarding neo4j functions, procedures, etc. can you please share? It would be much appreciated!

  • Neo4j 3.5.16


Hello @and_manousakis

By default, Neo4j uses its ids to sort the results (ascending id order) so in your case, it will return the node with the lowest identifier, if you want to sort the nodes, you can use ORDER BY + LIMIT:)


Hi @Cobra, thank you for the reply! It does solve my problem. :)


1 Like