UNION splices return values that have same alias from two RETURNs head-to-tail, unite the data of each return value in the same row as an integrated row and apply deduplication.
Syntax:
... return <expression1_A>
as <alias_A>
, <expression1_B>
as <alias_B>
, ...
UNION
... return <expression2_A>
as <alias_A>
, <expression2_B>
as <alias_B>
, ...
Input:
- <expression1>: Return values of the 1st RETURN
- <expression2>: Return values of the 2nd RETURN, should have the same number of return values as the 1st RETURN and the same data structure of each same alias
- <alias>: The alias of return value (different order allowed)
uncollect [1,2,3]) as a
uncollect [3,4,5]) as b
return a, b
union
uncollect [1,2]) as a
uncollect [3,5]) as b
return a, b
Each of the two UQLs above has return values a and b that are heterologous, their rows are spliced and data in each row are united before deduplication.

Common Usage
Example: Find cards that transferred to Card CA029 with an amount higher than 1000, and cards that transferred to Card CA022 with an amount higher than 3000, return results after deduplication
n({_id == "CA029"}).le({@transfer.amount > 1000}).n({@card} as n) return n
union
n({_id == "CA022"}).le({@transfer.amount > 3000}).n({@card} as n) return n