Different query results if variable path lenght is used


(Michael Horak) #1

I would like to ask why a query result is different when I am using a variable length path.

for example:

MATCH (n0:I {t:'n0'})-[:rel1 *0..1]->(n1)-[:rel2 *0..1]->(n2)<-[:rel3 *0..1]-(n3) RETURN n2;

this query returns n0,n1,n2,n2,n10 nodes

but if I don't use the variable path lenght

MATCH (n0:I {t:'n0'})-[:rel1]->(n1)-[:rel2]->(n2)<-[:rel3]-(n3) RETURN n2;

the result is only n2

Is there any way to use variable length path and return only the n2 ???

Thank you

(Andrew Bowman) #2

Using *1..1 should work the same as your second query.

Understand that by permitting a lower bound of 0, you are allowing there to be no relationship traversal at all, and that the nodes on either side of that relationship definition are allowed to be the same node.