Creating Lists

Largest Number of Actors

Write and execute a query to return the list of actors for a movie with a given title. Order and limit the results so that the movie title with the largest number of actors is returned.

Hint: There are multiple movies with the same title so you are aggregating by the movie title and not the movieID.

What movie title had the largest number of actors? (Enter a case-sensitive string for the movie title.)

  • ✓ Hamlet

Hint

Your MATCH clause will simply retrieve all actors who acted in a movie.

You will return the movie title, the list of actors for that movie title, the size of the list. Order the results by the size in descending order with a limit of 1

Use collect() to create the list of actors for all movies with a given title.

You should see that there are multiple movies with the same title so the aggregation will be for all movies with that title.

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

Once you have entered the answer, click the Try Again button below to continue.

Solution

You can run the following query to find the answer:

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

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

Once you have entered the answer, click the Try Again button below to continue.

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.

Chatbot

Hi, I am an Educational Learning Assistant for Intelligent Network Exploration. You can call me E.L.A.I.N.E.

How can I help you today?