Reputation: 5459
I started learning Neo4j last friday.
I've completed the Cypher examples on my local database, are there are some additional queries that I'd like to learn how to ask:
Given the three matrix movies, how do I list only actors that acted in all three of them? Or more generally, suppose I have a bunch of movies, actors and ACTS_IN relationships.
Given 3 movies:
Likewise, given 3 actors
Thanks!!
Upvotes: 2
Views: 862
Reputation: 33155
acted in all 3:
start m1=node:node_auto_index(title="The Matrix"),
m2=node:node_auto_index(title="The Matrix Reloaded"),
m3=node:node_auto_index(title="The Matrix Revolutions")
match a-[:ACTS_IN]->m1, a-[:ACTS_IN]->m2, a-[:ACTS_IN]->m3
return a;
acted in any: (easiest syntax is the union only from 2.0, so I'm going to go with that)
start m=node:node_auto_index(title="The Matrix")
match a-[:ACTS_IN]->m
return a, m
union
start m=node:node_auto_index(title="The Matrix Reloaded")
match a-[:ACTS_IN]->m
return a, m
union
start m=node:node_auto_index(title="The Matrix Revolutions")
match a-[:ACTS_IN]->m
return a, m;
And they're basically the same for the other two queries, just switch title for name, and put the people's names, and swap m for a in the start clause. :)
Upvotes: 3