Reputation: 2028
I'm struggling to write a cypher-query.
Graph
The picutre bellow shows the complete graph. Some movies do not have a stuntman (the graph is fictional).
Question
I wanna get ALL ACTORS (and THEIR MOVIES) who never played in a movie with a stuntman. In this case it would be "Johnny Depp"
Upvotes: 4
Views: 1485
Reputation: 11216
I think this will get you going
// Find the actors and their movies
MATCH (a:Actor)--(m:Movie)
// where the actor was never in a movie with a stuntman
WHERE NOT (a)-[:ACTS_IN]-(:Movie)-[:ACTS_IN]-(:Stuntman)
RETURN a,m
Upvotes: 2
Reputation: 7458
This should work :
MATCH (n:Actor)-->(m:Movie)
WHERE NOT (n)-->()<--(:Stuntman)
RETURN n AS actor, collect(m) AS movies
Cheers
PS: there is an other solution, but less performant I think :
MATCH (n:Actor)-->(m:Movie)
WITH n AS actor, collect(m) AS movies
WHERE all(m IN movies WHERE not (m)<--(:Stuntman))
RETURN actor, movies
Upvotes: 4