Imagine my query results in nodes with different names, but in my next query, I want to search in the merged version of the previous result. How can I merge two lists or two set of nodes? As an example, imagine I have
(:class1)-->(c1:class2)-->(:class3)--(:class4)-->(c2:class2)
and then I would like to do a MATCH based on the distinct elements in the merge of c1.name and c2.name.
The trick I learned somewhere to make this work is
MATCH (:class1)-->(c1:class2)-->(:class3)--(:class4)-->(c2:class2)
WITH collect(c1)+collect(c2) as nodez
UNWIND nodez as c
RETURN c
Note that you can't combine lists of different types (eg. nodes+relationships) this way. They have to all be the same type (eg. all nodes or all relationships). If you want to mix types in an aggregate list, you will need to convert everything to be the same type first (probably map).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With