UNION

UNION combines the results of two or more queries into a single result set that includes all the rows that belong to any queries in the union.

The number and the names of the columns must be identical in all queries combined by using UNION.

To keep all the result rows, use UNION ALL. Using just UNION will combine and remove duplicates from the result set.

If any of the queries in a UNION contain updates, the order of queries in the UNION is relevant.

Any clause before the UNION cannot observe writes made by a clause after the UNION. Any clause after UNION can observe all writes made by a clause before the UNION.

For details see clause composition in queries with UNION for details.

graph union clause

Combine two queries and retain duplicates

Combining the results from two queries is done using UNION ALL.

Query
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.

Table 1. Result
name

"Anthony Hopkins"

"Helen Mirren"

"Hitchcock"

"Hitchcock"

Rows: 4

Combine two queries and remove duplicates

By not including ALL in the UNION, duplicates are removed from the combined result set.

Query
MATCH (n:Actor)
RETURN n.name AS name
UNION
MATCH (n:Movie)
RETURN n.title AS name

The combined result is returned, without duplicates.

Table 2. Result
name

"Anthony Hopkins"

"Helen Mirren"

"Hitchcock"

Rows: 3