# How does the LIMIT clause work?

**URL:** <https://community.neo4j.com/t/how-does-the-limit-clause-work/18998>\
**Category:** Cypher\
**Tags:** cypher\
**Created:** [May 21, 2020, 8:34am UTC](https://community.neo4j.com/t/how-does-the-limit-clause-work/18998 "2020-05-21T08:34:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![and\_manousakis](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/and_manousakis/32/11628_2.png) [@and\_manousakis](https://community.neo4j.com/u/and_manousakis)\
**Post date:** [May 21, 2020, 8:34am UTC](https://community.neo4j.com/t/how-does-the-limit-clause-work/18998/1 "2020-05-21T08:34:51Z")

</div>

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

Thanks!  
Andreas

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [May 21, 2020, 12:33pm UTC](https://community.neo4j.com/t/how-does-the-limit-clause-work/18998/2 "2020-05-21T12:33:43Z")

</div>

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:)

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![and\_manousakis](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/and_manousakis/32/11628_2.png) [@and\_manousakis](https://community.neo4j.com/u/and_manousakis)\
**Post date:** [May 23, 2020, 8:11am UTC](https://community.neo4j.com/t/how-does-the-limit-clause-work/18998/3 "2020-05-23T08:11:32Z")

</div>

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

Best  
Andreas
