Reputation: 1531
MATCH (n), (n)-[:connected_to {status: 2}]-(sp:StayPal)
OPTIONAL MATCH (n)-[:connected_to {status: 1}] - (mutual_friend)-[:connected_to {status: 1}]-(sp)
WHERE (ID(n) = {ID_n})
RETURN DISTINCT sp, collect(mutual_friend)
I am trying to fetch all connection of n(staypal) having status = 2 and also with that all mutual connection of n and sp, but I am getting wrong results
Any help?
Upvotes: 0
Views: 216
Reputation: 30397
The location of the WHERE clause is significant, as it applies to the preceding clause. Place it under your MATCH, not the OPTIONAL MATCH.
Remember that the behavior of OPTIONAL MATCH is to find a match, and if no match is found (including if the OPTIONAL MATCH's WHERE clause evaluates to false), then the newly introduced variables will be set to null.
Also, there's no need to have the match to (n) apart from the pattern match. Just use MATCH (n)-[:connected_to {status: 2}]-(sp:StayPal)
for the first line.
Upvotes: 1