Get nodes which are not connected to specific node in Neo4j

Viewed 2085

I want to get all the nodes which are not connected to the given set of nodes. Suppose I've 5 nodes A,B,C,D,E. Now A->B->C are connected with the :Is_Friend relationship. Now I want all the nodes which are not connected to A (i.e D and E).

I tried this query but it's not working

MATCH (a:Friend{name:"A"})-[:Is_Friend_Of*]->(b:Friend) 
MATCH (c:Friend) 
WHERE NOT (c)-[:Is_Friend_Of]->(b)
RETURN c
1 Answers
Related