UNION ALL operator in BigQuery

The UNION ALL operator in BigQuery is used to concatenate the result sets of two or more SELECT queries into a single result set.

Unlike UNION, the UNION ALL operator does not remove duplicate rows. Every row returned by each SELECT statement is included in the final output.

Handling Duplicate Rows

BigQuery provides two UNION variants to control duplicate handling:

SQL Syntax

SELECT column1, column2, ...
FROM `project.dataset.table1`
[WHERE conditions]

UNION ALL

SELECT column1, column2, ...
FROM `project.dataset.table2`
[WHERE conditions];    

Key Points

Example: Combine sales data from two regions.

SQL

SELECT order_id, customer_id, order_amount
FROM `project.dataset.sales_india`

UNION ALL

SELECT order_id, customer_id, order_amount
FROM `project.dataset.sales_usa`;