[added] This is somewhat of a duplicate of my other post, but I thought it be a good request to ask for a set operator (DIFFERENCE) to be added to the existing UNION operator.
Hi @clem , is the movie title to be queried is the other way around. Because, I just queried from the movie sample dataset, Matrix and Matrix Revolutions and "The Matrix" has one extra actor. So I think Who all acted in Matrix but not in Matrix Revolutions.
Anyways, my method , you can use a List Compression ,
MATCH (p1:Person)-[:ACTED_IN]->(m:Movie {title:"The Matrix"})
with collect (p1.name) as matrix_list
MATCH (p2:Person)-[:ACTED_IN]->(m:Movie {title:"The Matrix Revolutions"})
with collect (p2.name) as matrix_rev_list, matrix_list
return [n in matrix_list WHERE NOT n in matrix_rev_list ] as actors
╒═══════════════╕
│"actors" │
╞═══════════════╡
│["Emil Eifrem"]│
└───────────────┘
For your debugging of the data
MATCH (p1:Person)-[:ACTED_IN]->(m:Movie {title:"The Matrix"})
with collect (p1.name) as matrix_list
MATCH (p2:Person)-[:ACTED_IN]->(m:Movie {title:"The Matrix Revolutions"})
with collect (p2.name) as matrix_rev_list, matrix_list
return matrix_list, matrix_rev_list
╒═════════════════════════════════════════════════════════════════════════════════════╤═══════════════════════════════════════════════════════════════════════╕
│"matrix_list" │"matrix_rev_list" │
╞═════════════════════════════════════════════════════════════════════════════════════╪═══════════════════════════════════════════════════════════════════════╡
│["Emil Eifrem","Hugo Weaving","Laurence Fishburne","Carrie-Anne Moss","Keanu Reeves"]│["Hugo Weaving","Laurence Fishburne","Carrie-Anne Moss","Keanu Reeves"]│
└─────────────────────────────────────────────────────────────────────────────────────┴───────────────────────────────────────────────────────────────────────┘
MATCH (p:Person)-[:ACTED_IN]->(:Movie {name:"The Matrix"})
WHERE NOT EXISTS { (p) -[:ACTED_IN]-> (:Movie {name:"The Matrix Revolutions"}) }
RETURN p
The dominicvivek06 answer was not bad and for many cases might be more optimised. It's always better to return only the property(ies) you need.
Neo4j relies on two "world", the graph and the projected data from it.
It's always better to stay as less as possible in the graph world and work in the projected data world. The clauses RETURN and WITH are projecting clauses.
You can read more about the projection principle in the neo4j cypher manual if you want to know why the dominicvivek06 answer is probably better even if it seems more longer and complicated.