Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypher: Avoid duplicate nodes

Have the below relationship

Bob-[:TWINS]-Alice

I need to return all twins. Below is the cypher being used but returns duplicates

MATCH a-[:TWINS]-b 
RETURN a.name, b.name

I've set this up in Neo4j console here.

How not to return duplicates? I know this can be easily fixed by including the direction of the relationship but here the direction is not relevant. So wondering how to avoid duplicates.

like image 241
Aravind Yarram Avatar asked Jul 04 '26 22:07

Aravind Yarram


1 Answers

This is the classic way:

MATCH a-[:TWINS]-b
WHERE id(a) < id(b)
RETURN a, b
like image 173
Eve Freeman Avatar answered Jul 07 '26 12:07

Eve Freeman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!