Eliminating Duplicates

Eliminating duplicate names

Eliminate Duplicate Names in Rows

This query 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

Using the clause DISTINCT in the RETURN clause will only return distinct values.

Solution

The answer is 166.

You can view the result with this 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

Summary

In this challenge, you modified a query to eliminate duplicate results.

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