UNION clause is used to combine the result of multiple queries.
It combines the results of two or more queries into a single result set that includes all the rows that belong to all queries in the union.
The number and the names of the columns must be identical in all queries combined by using
To keep all the result rows, use
UNION will combine and remove duplicates from the result set.
Combine two queries
Combining the results from two queries is done using
MATCH (n:Actor) RETURN n.name AS name UNION ALL MATCH (n:Movie) RETURN n.title AS name
The combined result is returned, including duplicates.
Combine two queries and remove duplicates
By not including
ALL in the
UNION, duplicates are removed from the combined result set
MATCH (n:Actor) RETURN n.name AS name UNION MATCH (n:Movie) RETURN n.title AS name
The combined result is returned, without duplicates.