# How to get the nth similar nodes in node similarity algorithm

**URL:** <https://community.neo4j.com/t/how-to-get-the-nth-similar-nodes-in-node-similarity-algorithm/39279>\
**Category:** Neo4j Graph Platform\
**Tags:** cypher\
**Created:** [June 3, 2021, 8:06am UTC](https://community.neo4j.com/t/how-to-get-the-nth-similar-nodes-in-node-similarity-algorithm/39279 "2021-06-03T08:06:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhishekjayant1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/abhishekjayant1/32/4175_2.png) [@abhishekjayant1](https://community.neo4j.com/u/abhishekjayant1)\
**Post date:** [June 3, 2021, 8:06am UTC](https://community.neo4j.com/t/how-to-get-the-nth-similar-nodes-in-node-similarity-algorithm/39279/1 "2021-06-03T08:06:37Z")

</div>

I ran similarity algo (GDS) on a memory graph, this gives me this result (showing the result in the table format):

 ![1](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/1/5/1590df43f8ae47ea09e4061b3701c1eb4f28e1fb.png)

If I want to return the top similarity pair, I can use limit 1 instead of 3 to get the top result. (Result with the maximum similarity).

But I want to only return the third most similar similarity pair, how can I do that?  
Basically, my result should be something like this:

 ![2](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/9/f/9fd098cbd5fa7bc40b4dfeb0e65241f6f6794371.png)

---

<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:** [June 3, 2021, 9:58am UTC](https://community.neo4j.com/t/how-to-get-the-nth-similar-nodes-in-node-similarity-algorithm/39279/2 "2021-06-03T09:58:58Z")

</div>

Hello @abhishekjayant1 🙂

You should have a look at [SKIP](https://neo4j.com/docs/cypher-manual/current/clauses/skip/), in your case:

```auto
ORDER BY similarity DESC SKIP 2 LIMIT 1

```

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![abhishekjayant1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/abhishekjayant1/32/4175_2.png) [@abhishekjayant1](https://community.neo4j.com/u/abhishekjayant1)\
**Post date:** [June 3, 2021, 10:33am UTC](https://community.neo4j.com/t/how-to-get-the-nth-similar-nodes-in-node-similarity-algorithm/39279/3 "2021-06-03T10:33:52Z")

</div>

Hi @Cobra , thanks for helping out again 🙂 . This is exactly what I wanted.  
However, can you also tell me how to exclude the duplicate similarity pair when I run the node similarity algo. I've shown the duplicate pairs below:

 ![1](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/a/5/a50589c8f4a4c0df08734a3bf78ec6f0ccb46ed4.png)

I get these duplicate pairs, how can I get rid of these?  
PS: I do now want to use write mode, only want to use stream.

---

<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:** [June 3, 2021, 11:44am UTC](https://community.neo4j.com/t/how-to-get-the-nth-similar-nodes-in-node-similarity-algorithm/39279/4 "2021-06-03T11:44:48Z")

</div>

You can modify your `WHERE` clause like this:

```auto
WHERE n1:Adverse_Event
AND n2:Adverse_Event
AND id(n1) > id(n2)

```

---

<div class="post-metadata">

**Author:** ![abhishekjayant1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/abhishekjayant1/32/4175_2.png) [@abhishekjayant1](https://community.neo4j.com/u/abhishekjayant1)\
**Post date:** [June 3, 2021, 12:44pm UTC](https://community.neo4j.com/t/how-to-get-the-nth-similar-nodes-in-node-similarity-algorithm/39279/5 "2021-06-03T12:44:22Z")

</div>

Solved the problem. Thank you so much! 😁
