Oldest Actor

Oldest Actor

Here is a query that returns the actors who acted in movies in 2000 and who have a value for the born property.

cypher
MATCH (a:Actor)-[:ACTED_IN]->(m:Movie)
WHERE m.year = 2000
AND a.born IS NOT NULL
RETURN DISTINCT a.name AS Actor, a.born AS Born

Rewrite this query to:

  1. Sort the actors by the born property.

  2. Create a list from the sorted actor nodes.

  3. Return the name and birth date of the oldest actor.

What is the name of the oldest actor who acted in a movie released in the year 2000?

Once you executed, enter the name below and click Check Answer.

  • ✓ Ossie Davis

Hint

Add a WITH clause to sort the actors. Add a WITH clause to create the list of actors from the sorted nodes retrieved. RETURN the name of the first element of the list

What is the name of the oldest actor who acted in a movie released in the year 2000?

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)
WHERE m.year = 2000
AND a.born IS NOT NULL
WITH a ORDER BY a.born
WITH collect(DISTINCT a) AS Actors
RETURN head(Actors).name, head(Actors).born

What is the name of the oldest actor who acted in a movie released in the year 2000?

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

Summary

In this challenge, you wrote a query that uses head() to return the oldest actor for a given year.

In the next challenge, you will write a query to perform a calculation on all elements in a list.