cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to match and not match?

clem
Graph Steward

Suppose I want actors who were in "The Matrix" but not "The Matrix Revolutions"

I want to do something like:

MATCH(p:Person) -[:ACTED_IN]-> (:Movie {name:"The Matrix"})
NOT MATCH(p) -[:ACTED_IN]-> (:Movie {name:"The Matrix Revolutions"})
RETURN p

which is not legal. I'm not sure how to do this.... Google didn't return anything useful but maybe I didn't ask in the best way.

Thanks in advance.

(If there was a DIFFERENCE operator in addition to UNION or INTERSECTION would be useful too.)

[Added] I made a separate request for DIFFERENCE feature post here: WANT DIFFERENCE operator. I didn't intend to make it a duplicate.

6 REPLIES 6

Hi @clem , answered in your other post too .

Link -> WANT DIFFERENCE operator - #2 by dominicvivek06

Two times in the same post

Please consider your own post before posting the same thing.
It's even worst then not searching before posting.

@tard.gabriel - if you look at my post, a link to the original post included., just like yours.

Sorry for the confusion dominicvivek06
My last answer was intended to clem.
He created two post for exactly the same subject, probably trying to get a better answer knowing that answered post are more unlikely to be answer again, or just a mistake.

For my taste your answer works. I gave him exactly what he wanted but not sure if the WHERE EXISTS subclause is optimal in this case. I'm try to get better in the underlying neo4j query tunning.

[added] This is somewhat of a duplicate of my other post, but I thought it be a good request to ask for a set operator (DIFFERENCE) to be added to the existing UNION operator. With a DIFFERENCE operator, I think the query would be conceptually cleaner, which is why I am suggesting it.

The WHERE [NOT] EXISTS { } subclause is definitively more sexy on the eyes and easier to use but if you are in a production environment the dominicvivek06 solution might be quicker I don't know.

I would be curious to compare both