cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

In Exercise 4.11, why directors are not listed in the actor column?

Hi All,

Either with the tutorial command

MATCH (a1:Person)-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(a2:Person)
WHERE exists( (a2)-[:DIRECTED]->(m) )
RETURN a1.name as Actor, a2.name as Actor/Director, m.title as Movie

or with this command

match (p:Person) -[:ACTED_IN]-> (m:Movie) <-[:DIRECTED]- (p), (ac:Person) -[:ACTED_IN]-> (m)
return ac.name as actor, p.name as director, m.title as movie

Even if we know that directors are also actors, they are not listed in the actor column.
Can someone explain me why?

Regards,
Patrick

1 REPLY 1

Sure.

So in the first query, the requirement is we're finding the entire pattern, and one of the requirements of this pattern is that whoever is matched to a2 has to have also directed the movie.

The movies in question ("That Thing You Do", "Unforgiven", and "Hoffa") only have a single director each.

So while we could possibly have a1 match to the actor/director in all these cases, there is no other (a2) person who directed the movie, so the pattern cannot be fulfilled by binding the directors to a1.

Now if there was a second director on each of these movies, and that second director also happened to act in the movie, then we could successfully match on that pattern.

Note also that relationships must be unique within matched patterns, which is why the same person from a1 cannot also be matched to a2, since it would require us to traverse the single :ACTED_IN relationship between them and the movie twice, which isn't allowed.

That is also why in the second query whoever we match to p cannot be bound to ac as well, because the single :ACTED_IN relationship between the person and the movie may only be traversed once per path, and it was already used in the first pattern, so it cannot be used in the second part of the pattern. This has the consequence that p and ac must be separate people.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit - November 16 - 17, 2022.


Free NODES Training Series


October 19th -

Intro to Neo4j


October 20th -

Healthcare Analytics Using Neo4j


October 25th -

Handling Neo4j data with Apache Hop


October 26th -

Blazing Fast Graphs: Hands-on with Apache Arrow and Neo4j


November 2nd -

Graph EDA Using the Neo4j GDS Client