Negation of Single Node


(Rcfro2) #1

The query below -

MATCH (p:Person)-[:WROTE]->(m:Movie)
WHERE NOT exists( (p)-[:DIRECTED]->() )
RETURN p.name, m.title

reads as such, correct?
"Match all people who wrote a movie who did not direct ANY movie"

It does not read as the following:
"Match all people who wrote a movie who did not direct THAT movie"

for it to be "that" movie, the query would have to include the following:
NOT exists( (p)-[:DIRECTED]->(m) )

Additionally, the following:

MATCH (gene:Person)-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(other:Person)
WHERE gene.name= 'Gene Hackman'
AND exists( (other)-[:DIRECTED]->() )
RETURN gene, other, m

Reads as -
"find Gene Hackman and ANY movie that he acted in
with another person who also directed ANY movie"

And NOT as -
"find Gene Hackman and THE movies that he acted in
with another person who also directed THE movie"

correct?


(Andrew Bowman) #2

Yes, all your assumptions here are correct. Note that in your WHERE clause the exists() function isn't really needed, it's enough to do WHERE <pattern> or WHERE NOT <pattern>