1
votes

I have a neo4j graph where A-[r:LOVE]->B and B-[r:LOVE]->A.

I'm trying to get all the nodes with that bidirectional relationship (some nodes for example C-[r:LOVE]->B but B not love C) and I must get them only 1 time (i don't want to get them duplicated) and ordered by name. I'm trying to use the following:

Match (n)-[r:LOVE]->(n1) return distinct n,n1 order by n.Name

But that give me all the nodes with the relationship: LOVE between some of then(even if it's not bidirectional).

How can i fix it?

1

1 Answers

3
votes

To find all pairs of people having two, differently directed LOVE relationships in between:

MATCH (a)-[:LOVE]->(b)<-[:LOVE]-(a)
WHERE id(a)<id(b)
RETURN a,b order by a.name

The WHERE condition here makes sure that a and b do not change roles in a subsequent iteration.