cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Cypher query

jpl
Node

I have many person nodes with a name property. I have one relationship "likes".

What is the query for "Who are the persons that like Ed but do not like (have no relationship with) Alice, Bob, Charlie, and Dan?"

1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

try this: 

match(p:Person)-[:LIKES]->(:Person{name: β€˜Ed’})

where not exist ((p)-[:LIKES]->(:Person{name: β€˜Alice’}))

and not exist ((p)-[:LIKES]->(:Person{name: β€˜Bob’}))

and not exist ((p)-[:LIKES]->(:Person{name: β€˜Charli’}))

and not exist ((p)-[:LIKES]->(:Person{name: β€˜Dan’}))

return p.name as person

Same query with a little fancier notation:

with [β€œAlice”, β€œBob”, β€œDan”, β€œCharlie”] as names

match(p:Person)-[:LIKES]->(:Person{name: β€œEd”})

where none( x in names where exists ((p)-[:LIKES]->(:Person{name: x})))

return p.name as person

View solution in original post

1 REPLY 1

glilienfield
Ninja
Ninja

try this: 

match(p:Person)-[:LIKES]->(:Person{name: β€˜Ed’})

where not exist ((p)-[:LIKES]->(:Person{name: β€˜Alice’}))

and not exist ((p)-[:LIKES]->(:Person{name: β€˜Bob’}))

and not exist ((p)-[:LIKES]->(:Person{name: β€˜Charli’}))

and not exist ((p)-[:LIKES]->(:Person{name: β€˜Dan’}))

return p.name as person

Same query with a little fancier notation:

with [β€œAlice”, β€œBob”, β€œDan”, β€œCharlie”] as names

match(p:Person)-[:LIKES]->(:Person{name: β€œEd”})

where none( x in names where exists ((p)-[:LIKES]->(:Person{name: x})))

return p.name as person