cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Different query results if variable path lenght is used

Hello,
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

1 REPLY 1

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.