I am using UNION to combine the result of two queries into a single node list, which works as expected. However I would like to use this combined node set as input for the next match and I can't seem to get it right...
MATCH(n).....
RETURN n
UNION
MATCH(n).....
RETURN n
WITH n
MATCH(x)....->(n)
RETURN n, x;
Written as-is, it complains about the second RETURN not being at the end of the query.
If I omit it, the WITH part is interpreted as part of the second query.
At that point in the query, n is the only variable in scope, so you are not dropping variables out of scope, you are not introducing a new variable, you are not adding reads after writes, you are not filtering aggregates, you are not sorting results, you are not applying limits or where clauses
-> You do not need WITH