Combining Results

Combining actors and directors data

Actors and Directors from 2015

This query 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 name,
    collect(m.title) AS movies

Run this query and review the results.

Your challenge is to add another query to this code to return the directors for 2015.

Use UNION ALL to combine results. The second query should return the string "Director" as Type.

How many rows are returned?

  • ✓ 819

Hint

Create a similar query that returns information about directors using the DIRECTED relationship.

Combine the results from both queries using UNION ALL.

Solution

The answer is 819.

Run the following query to see the result:

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

UNION ALL

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

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.