Creating Lists

Actors by movie title

Return a list actors who have appeared in movies with the same title.

Update this query to:

  1. Return the actors as a list.

  2. Order the results by the size of the actors list.

cypher
MATCH (a:Actor)-[:ACTED_IN]->(m:Movie)
RETURN 
    m.title AS movie,
    ??????(a.name) AS actors
ORDER BY ??????(actors) DESC
LIMIT 100

There are multiple movies with the same title so the query aggregates by the movie title and not the movieID.

What movie title had the largest number of actors? (case-sensitive)

  • ✓ Hamlet

Hint

Use collect() to create the list of actors.

You can use the size() function to get the size of a list.

Solution

The answer is Hamlet.

Run the following query to see the result:

cypher
MATCH (a:Actor)-[:ACTED_IN]->(m:Movie)
RETURN 
    m.title AS movie,
    collect(a.name) AS actors
ORDER BY size(actors) DESC
LIMIT 100

Summary

In this challenge, you wrote a query to return lists of actors and order the lists to determine the largest list.

In the next challenge, you will answer another question using this same query.