OPTIONAL MATCH

Using OPTIONAL MATCH

Optionally returning rows

Here is the query you previously executed.

cypher
MATCH (m:Movie)-[:IN_GENRE]->(g:Genre)
WHERE g.name = 'Film-Noir'
MATCH (m)<-[:RATED]-(u:User)
RETURN m.title, u.name

Modify and execute this query so that the test for users who rated the movie are optional.

How many rows are returned?

  • ✓ 1152

Hint

You will prefix the MATCH clause with OPTIONAL.

Solution

You can run the following query to find the answer:

cypher
MATCH (m:Movie)-[:IN_GENRE]->(g:Genre)
WHERE g.name = 'Film-Noir'
OPTIONAL MATCH (m)<-[:RATED]-(u:User)
RETURN m.title, u.name

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

Summary

In this challenge, you modified a query and answered a question about what was retrieved which expanded the data returned to specify an OPTIONAL MATCH.

In the next module, you will learn about controlling results returned.