Reputation: 553
I am trying to get all Nodes (node1) that have relationship (relationship of type R1) to node2 and not having (relationship of type R2). I tried to run this query :
MATCH node1 -[r1: R1]-> node2 WHERE node2.id = '1234' WITH node1,node2
OPTIONAL MATCH node1- [r2: R2]->node2 WHERE r2 is NULL
RETURN content
I am stil getting nodes that have r2 relationship in the resulte. what is wrong with my query?
Upvotes: 3
Views: 3614
Reputation: 10856
I think what you want is MATCH
syntax in the WHERE
in a NOT
:
MATCH (node1)-[:R1]->(node2)
WHERE node2.id = '1234' AND NOT (node1)-[:R2]->(node2)
RETURN node1
Upvotes: 6