0
match (a)-[r:friend_of]-(b)  where a.name='john' return b.name

in this case it will giving all the nodes which are [r:friend_of] relation with john, but, I want those who are not [r:friend_of] relation with john so, can any plz help me, thanks in advance,

match (a)- NOT [r:friend_of]-(b)  where a.name='john' return b.name 

match (a)- <> [r:friend_of]-(b)  where a.name='john' return b.name

am trying this, but am not getting

cybersam
  • 63,203
  • 6
  • 53
  • 76
manjunath
  • 1
  • 1

2 Answers2

2

Cypher does not have a special syntax for finding "unrelated" nodes.

Here is one way to find people who are not friends with John:

MATCH (john:Person {name:'John'})-[:friend_of]-(f:Person)
WITH john, COLLECT(f) AS friends
MATCH (notFriend:Person)
WHERE NOT notFriend IN friends
RETURN notFriend

This query first gets a list of all the friends of John, and then returns the people who are not in that list.

cybersam
  • 63,203
  • 6
  • 53
  • 76
0

I'm reading your question as, Find all nodes that are related to nodes that have a name property value of "john" and that are not related by a "friend_of" relationship. If that's correct then I think this will do what you're looking for:

MATCH (a)-[r]-(b) WHERE TYPE(r) <> "friend_of" AND a.name = 'john' RETURN b.name
hoyski
  • 344
  • 1
  • 7