Either with the tutorial command
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?
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
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
ac must be separate people.