Part 3 of 5 · 1 min read
INTERSECT
Keeping only rows that appear in both result sets.
Think of comparing two guest lists and keeping only the names that appear on both.
In plain words: INTERSECT returns only the rows that appear in both of two queries' results. The same column-count-and-type rule applies as with UNION.
A worked example. Customers who ordered in both January and February.
The key lines.
SELECT customer_id FROM orders WHERE placed_on BETWEEN '2026-01-01' AND '2026-01-31'
INTERSECT
SELECT customer_id FROM orders WHERE placed_on BETWEEN '2026-02-01' AND '2026-02-28';
INTERSECT
INTERSECT returns only the rows present in both of two queries' results.
Example: a customer who ordered only in January, not February, is excluded from this result entirely.