1
votes

I am doing the exercises found in the :play intro-neo4j-exercises (exercise 4.10). Everything seems good, but I cannot understand exactly the difference between the two queries. Can someone please elaborate?

MATCH path =  (p:Person)-[:PRODUCED]->(m:Movie) 
WHERE NOT EXISTS( (p)-[:DIRECTED]->(:Movie) )
RETURN p.name, m.title

Returns:

|"a.name"      │"m.title"               │
╞══════════════╪════════════════════════╡
│"Joel Silver" │"The Matrix"            │
├──────────────┼────────────────────────┤
│"Joel Silver" │"The Matrix Reloaded"   │
├──────────────┼────────────────────────┤
│"Joel Silver" │"The Matrix Revolutions"│
├──────────────┼────────────────────────┤
│"Stefan Arndt"│"Cloud Atlas"           │
├──────────────┼────────────────────────┤
│"Joel Silver" │"V for Vendetta"        │
├──────────────┼────────────────────────┤
│"Joel Silver" │"Speed Racer"           │
├──────────────┼────────────────────────┤
│"Joel Silver" │"Ninja Assassin"        │
└──────────────┴────────────────────────┘

WHILE:

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

RETURNS:

╒═════════════════╤════════════════════════╕
│"a.name"         │"m.title"               │
╞═════════════════╪════════════════════════╡
│"Joel Silver"    │"The Matrix"            │
├─────────────────┼────────────────────────┤
│"Joel Silver"    │"The Matrix Reloaded"   │
├─────────────────┼────────────────────────┤
│"Joel Silver"    │"The Matrix Revolutions"│
├─────────────────┼────────────────────────┤
│"Nora Ephron"    │"When Harry Met Sally"  │
├─────────────────┼────────────────────────┤
│"Stefan Arndt"   │"Cloud Atlas"           │
├─────────────────┼────────────────────────┤
│"Lana Wachowski" │"V for Vendetta"        │
├─────────────────┼────────────────────────┤
│"Lilly Wachowski"│"V for Vendetta"        │
├─────────────────┼────────────────────────┤
│"Joel Silver"    │"V for Vendetta"        │
├─────────────────┼────────────────────────┤
│"Joel Silver"    │"Speed Racer"           │
├─────────────────┼────────────────────────┤
│"Lana Wachowski" │"Ninja Assassin"        │
├─────────────────┼────────────────────────┤
│"Joel Silver"    │"Ninja Assassin"        │
├─────────────────┼────────────────────────┤
│"Lilly Wachowski"│"Ninja Assassin"        │
└─────────────────┴────────────────────────┘
1

1 Answers

0
votes

The first query finds Persons who PRODUCED the Movie m, but did not direct any movie. The second query finds Persons who PRODUCED the Movie m but did not direct that particular Movie m. You know this because in the second query, the bound variable m is used in the WHERE clause, whereas in the first query, only the label :Movie is used in the WHERE clause.

Incidentally, the path = part of the first query does nothing.