Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypher query to check if list1 contains any item from list2

Tags:

neo4j

cypher

Every node in my DB has a property that holds a list. I need to check whether any item in a given list is in that property.

I'm looking for a query like match (n) where any(x in n.list where x=[101,102,103]) return n - which means "check if n.list contains 101, 102, 103. If so, return n"

Is there anything like that in cypher?

like image 599
Aviran Katz Avatar asked Sep 05 '16 09:09

Aviran Katz


1 Answers

You pretty much have the answer to your question !

Check this : https://neo4j.com/docs/cypher-manual/current/functions/predicate/#functions-any, the any predicate exists.

The only error in your query is x=[101,102,103] that you should change by x IN [101,102,103]

So the final query is :

MATCH (n) 
WHERE any(x IN n.list WHERE x IN [101,102,103])
RETURN n
like image 53
logisima Avatar answered Oct 05 '22 23:10

logisima