UNION splices return values that have same alias from two RETURNs head-to-tail and unite the data of each return value in the same row as an integrated row. It has an operational efficiency higher than that of UNION since no deduplication is executed against the united rows.
Syntax:
... return <expression1_A>
as <alias_A>
, <expression1_B>
as <alias_B>
, ...
UNION ALL
... 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 all
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.

Common Usage
Example: Find cards that transfered to Card CA029 with an amount higher than 1000, and cards that transfered 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 all
n({_id == "CA022"}).le({@transfer.amount > 3000}).n({@card} as n) return n