cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Cypher query for subset

kaptenh
Node Clone

Hi,
I have to lists, say A and B. I want to check if all elements of B are contained in A, i.e if B is a subset of A..
More specifically I have a list of labels and I want to find nodes having all those labels, and they can possibly have more labels.
I have tried various of collect, all and so on and cant find a good way. Any suggestions?

Thanks

1 REPLY 1

You can use a list predicate to ensure a condition exists for all elements of a list:

WITH listA, listB
WHERE all(element in listB WHERE element in listA)

If you're starting from nodes and want to check this for node labels, then something like:

WITH nodeA, nodeB
WHERE all(label in labels(nodeB) WHERE label in labels(nodeA))