Combining Results

Combining actors and directors data

Actors and Directors from 2015

Here is a query that returns actor information for the year 2015:

cypher
MATCH (m:Movie)<-[:ACTED_IN]-(p:Person)
WHERE m.year = 2015
RETURN "Actor" AS type,
p.name AS workedAs,
collect(m.title) AS movies

Execute this query to see what it returns.

Now add another query to this code to return the directors for 2015. Use UNION ALL to combine results. The second query will return the string "Director" as Type.

How many rows are returned?

  • ✓ 819

Hint

At the end of the starter code add: UNION ALL

Then repeat the code, but modify it to return information about directors.

How many rows are returned?

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 (m:Movie)<-[:ACTED_IN]-(p:Person)
WHERE m.year = 2015
RETURN "Actor" AS type,
p.name AS workedAs,
collect(m.title) AS movies
UNION ALL
MATCH (m:Movie)<-[:DIRECTED]-(p:Person)
WHERE m.year = 2015
RETURN "Director" AS type,
p.name AS workedAs,
collect(m.title) AS movies

How many rows does it return?

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

Summary

In this challenge, you answered a question by writing a Cypher statement to combine results.

In the next module, you will learn about using parameters in Cypher.

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?