Exercise 4.11 in intro-neo4j-exercises

This is a good question, and the solution query in the exercise probably isn't the best, now that I look at it.

As you say, in a special case with a movie with a single actor who both acted in and directed the movie, the solution query will NOT find this pattern, for exactly the reason you specified, the MATCH pattern requires at least two actors in the movie.

Another problem is that for movies with multiple actors who-are-also-the-directors, we're going to get duplicate results, since we get the full cast of results per actor-who-is-also-the-director.

A better solution might be something like:

MATCH (m:Movie)<-[:DIRECTED]-(a2:Person)
WHERE (m)<-[:ACTED_IN]-(a2)
WITH m, collect(a2.name) as directors
OPTIONAL MATCH (m)<-[:ACTED_IN]-(a1)
WHERE NOT a1 IN directors
RETURN  a1.name as Actor, directors as `Actor/Director(s)`, m.title as Movie
1 Like