UNION, INTERSECT & EXCEPT
◈ 2 cardsCombine the rows of two queries as sets.
Stack query results
Set operators combine the rows of two SELECTs that have the same columns:
UNION— all rows from both, duplicates removedUNION ALL— all rows, duplicates kept (faster — use when you know there are none)INTERSECT— only rows in bothEXCEPT— rows in the first but not the second
SELECT book_id FROM order_items
INTERSECT
SELECT book_id FROM reviews;
Column names come from the first query; the column types must line up.