Showing results for 
Search instead for 
Did you mean: 

Potentially incorrect answer to Exercise 6.4 in "4.0-intro-neo4j-exercises"

The exercise is: "Retrieve all directors, their movies, and people who acted in the movies, returning the name of the director, the number of actors the director has worked with, and the list of actors." However, the posted answer doesn't include the movies.

Posted answer:
"MATCH (d:Person)-[:DIRECTED]->(m:Movie)<-[:ACTED_IN]-(a:Person) RETURN AS director, count(a) AS number actors , collect( AS actors worked with"

I believe the correct (or more complete) answer is:
MATCH (d:Person)-[:DIRECTED]->(m:Movie)<-[:ACTED_IN]-(a:Person)
RETURN AS director, collect(DISTINCT m.title) AS movies directed, count(a) AS number actors , collect( AS actors worked with

(I'm still trying to understand why I need to include DISTINCT to prevent duplicate movie titles. An earlier post about exercise 6.3 seems close but I'm not sure it directly relates to this query.)


Welcome @lukas.mcmichael to the Community!

The description of the query and the return specification does not include the list of movies, but you can certainly return them.

The DISTINCT is used to eliminate duplicate elements in a list or in a set of rows returned so it is the right thing to do.


Nodes 2022
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.