Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-19-2019 03:49 AM
I am using Neo4J browser version - Neo4j is 3.5.
I am learning Cypher by ":play intro-neo4j-exercises" command in Neo4j browser.
My question is one of the exercise below, I am not able to understand this query :
Exercise 4.11: Retrieve the movies and their actors where one of the actors also directed the movie (Solution)
Retrieve the movies and their actors where one of the actors also directed the movie, returning the actors names, the director’s name, and the movie title.
Solution is:
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
Questions:
I am not able to understand first line in the above code.
Any difference if we reference node by variable or by node type , like if I refer WHERE clause with (m) or (:Movie)
05-19-2019 03:52 PM
Answer
1.) The first line is searching for a pattern. The pattern must contain a Movie with 2 Person nodes connected via ACTED_IN relationships. An example of something that would not be included: A movie which had no actors, a person which was not connected to a movies with multiple actors in it, A movie with only 1 person it (that only had one relationship to the movie).
2.) The Where exists will be different if you reference (:Movie) vs (m). Suppose you had (:Movie) instead of (m), then in this case you will allow the actor to have directed ANY movie, not just a move he acted in. By using (m) you force the query to look for actors who both acted AND directed in the same movie.
05-30-2019 09:23 AM
Thanks a lot, it is perfect.
All the sessions of the conference are now available online