# How can I add a condition in "SIMILARITY"

**URL:** <https://community.neo4j.com/t/how-can-i-add-a-condition-in-similarity/1764>\
**Category:** Graph Data Science / Graph Analytics\
**Tags:** cypher\
**Created:** [September 25, 2018, 9:00am UTC](https://community.neo4j.com/t/how-can-i-add-a-condition-in-similarity/1764 "2018-09-25T09:00:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mehdi.ajroud](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mehdi.ajroud/32/1045_2.png) [@mehdi.ajroud](https://community.neo4j.com/u/mehdi.ajroud)\
**Post date:** [September 25, 2018, 9:00am UTC](https://community.neo4j.com/t/how-can-i-add-a-condition-in-similarity/1764/1 "2018-09-25T09:00:37Z")

</div>

Excuting the query of similarity was successuful by using this :

```auto
MATCH (at1:Attrib)<-[r:ASSIGNED]-(c:Contrat)-[x:ASSIGNED]->(at2:Attrib)
MERGE (at1)-[s:SIMILARITY]-(at2)

```

And then , to display only Attribs which are working together , I worked with this query and it's fine :

```auto
MATCH (at:Attrib)<-[r]-(c:Contrat)
WITH DISTINCT c.id AS Contrat , collect(DISTINCT at.label) AS Attributaires, count( DISTINCT at.id) AS Count
Return Attributaires;

```

and this the result :

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/1/17cc1fb889dfa78f93370ea87e57ecb9b48e3abb.png)

My question is how can I remove duplicates for "at" in the graph and not only in the list . if 2 at have the same ID and they re displayed then we display only one at .

---

<div class="post-metadata">

**Author:** ![mark.needham](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mark.needham/32/104_2.png) [@mark.needham](https://community.neo4j.com/u/mark.needham)\
**Post date:** [September 25, 2018, 10:51am UTC](https://community.neo4j.com/t/how-can-i-add-a-condition-in-similarity/1764/2 "2018-09-25T10:51:06Z")

</div>

I'm not sure that I understand exactly what you'd like to do...could you maybe share a sample dataset that I can create locally and then say what you'd like the output of your query to be?

---

<div class="post-metadata">

**Author:** ![mehdi.ajroud](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mehdi.ajroud/32/1045_2.png) [@mehdi.ajroud](https://community.neo4j.com/u/mehdi.ajroud)\
**Post date:** [September 25, 2018, 11:28am UTC](https://community.neo4j.com/t/how-can-i-add-a-condition-in-similarity/1764/3 "2018-09-25T11:28:55Z")

</div>

Actually this is the graph that I obtained after excuting "similarity" .

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/1/1a7a68bc88107f771eb221eee40435448d02e25e.jpeg)  
And here is the list of "Attributes" which are working together :  
 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/c/c5d81fda727a13c05eaf821cf2683abc3b282040.png)

What I want to do exactly is : deleting the duplicates nodes which have the same ID (ID : 111 apearing twice for example here in the graph , I want to havejust one instead of two nodes with the same ID .

---

<div class="post-metadata">

**Author:** ![mehdi.ajroud](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mehdi.ajroud/32/1045_2.png) [@mehdi.ajroud](https://community.neo4j.com/u/mehdi.ajroud)\
**Post date:** [September 25, 2018, 11:43am UTC](https://community.neo4j.com/t/how-can-i-add-a-condition-in-similarity/1764/4 "2018-09-25T11:43:09Z")

</div>

Here is the solution :

> <https://gist.github.com/jruts/fe782ff2531d509784a24b655ad8ae76>
