Available Tables

Next →

UNION vs UNION ALL

The UNION and UNION ALL operators are used to combine results from multiple SELECT statements. Both require the same number of columns and compatible data types in each query.

UNION

Example:

SELECT customer_id FROM Customers
UNION
SELECT customer_id FROM Orders;

UNION ALL

Example:

SELECT customer_id FROM Customers
UNION ALL
SELECT customer_id FROM Orders;

Key Difference

If a customer_id appears in both Customers and Orders: