Eliminating Duplicates

Eliminating duplicate names

Eliminate Duplicate Names in Rows

Here is a query that returns the names people who acted or directed the movie Toy Story and then retrieves all people who acted in the same movie.

Execute this query. It will return 183 rows, some of which are duplicates.

cypher
MATCH (p:Person)-[:ACTED_IN| DIRECTED]->(m)
WHERE m.title = 'Toy Story'
MATCH (p)-[:ACTED_IN]->()<-[:ACTED_IN]-(p2:Person)
RETURN  p.name, p2.name

Modify the query to eliminate duplicate rows.

How many rows are now returned?

  • ✓ 166

Hint

You will use DISTINCT in the RETURN clause.

Solution

This is the modified query:

cypher
MATCH (p:Person)-[:ACTED_IN| DIRECTED]->(m)
WHERE m.title = 'Toy Story'
MATCH (p)-[:ACTED_IN]->()<-[:ACTED_IN]-(p2:Person)
RETURN  DISTINCT p.name, p2.name

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 modified a query to eliminate duplicate results.

In the next lesson, you will learn about changing results returned.