cancel
Showing results forΒ
Did you mean:Β

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

## Cypher query

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
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

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