1
votes

If I have a linked series of nodes: A<--B-->C-->D

match (n)-[r]-(m) return n,r,m will give me [A,B],[B,A],[B,C],[C,B],[C,D],[D,C].

What if I want to return only one of each pair: [A,B], [B,C], [C,D]?

How do I discard the 'duplicates' that come from ignoring the path direction? The nature of this data is such that path directions are fluid and unpredictable. I can get the answer in code with the duplicated results but I'm wondering if there is a way to get neo4j to do the work in advance.

1

1 Answers

0
votes

Use the direction arrow:

match (n)-[r]->(m) return n,r,m

if you want to have undirected paths, the pair will be returned twice

you can limit that by imposing order.

match (n)-[r]->(m) where id(n) < id(m) return n,r,m