1 / 8

PostgreSQL ยท Joins & aggregations

Combine compatible result shapes

UNION, INTERSECT, and EXCEPT combine the outputs of two queries. Each branch must return the same number of columns, and corresponding columns must have compatible types.

SELECT email FROM customers
UNION
SELECT email FROM newsletter_signups;

UNION includes rows from either result and removes duplicates. Set operations combine rows, not tables or schemas; each branch can still have its own WHERE clause.