Find Actors with Common Movies

Write a query to find all actors who satisfy the following conditions:

  • The actor had played together with Tom Hanks in a movie that was released before or in 1995, AND
  • The actor has not played together with Tom Hanks in a movie that was released after 1995.

Eleven actors in the graph satisfy the above conditions - 11 records returned in total.

The data set for this query is the default Movie database in Neo4j.

This is one approach:

match(n:Person{name: 'Tom Hanks'})-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(o:Person) 
where m.released <= 1995
and not exists {
    match(n)-[:ACTED_IN]->(x:Movie)<-[:ACTED_IN]-(o) 
    where x.released > 1995
}
return distinct o.name

Thanks, it works!
(migrated from khoros post Solved: Re: Find Actors with Common Movies - Neo4j - 60969)