I am new to Neo4j and going through their introduction tutorial and I am a little bit confused about the use of the 'WHERE NOT exists' clause. The tutorial shows an example where they want to return all Person nodes of people who wrote movies and exclude people who directed that movie. Their query for this is:
MATCH (p:Person)-[:WROTE]->(m:Movie)
WHERE NOT exists( (p)-[:DIRECTED]->() )
RETURN p.name, m.title
which returns:
p.name m.title
"Aaron Sorkin" "A Few Good Men"
"Jim Cash" "Top Gun"
"David Mitchell" "Cloud Atlas"
My query for this is:
MATCH (p:Person)-[:WROTE]->(m:Movie)
WHERE NOT exists( (p)-[:DIRECTED]->(m) )
RETURN p.name, m.title
which returns:
p.name m.title
"Aaron Sorkin" "A Few Good Men"
"Jim Cash" "Top Gun"
"Nora Ephron" "When Harry Met Sally"
"David Mitchell" "Cloud Atlas"
"Lana Wachowski" "V for Vendetta"
"Lilly Wachowski" "V for Vendetta"
I checked the graph relationships for "Nora Ephron", "Lana Wachowski" and "Lilly Wachowski" (who are not in their query result) and found that they wrote and produced the movies (but not directed). According to my understanding both of the queries should return the same result. I am wondering why they are returning different results. Any help would be appreciated for explaining the differences.