Anti-Joins and Semi-Joins (NOT EXISTS)
Find 'rows in A with no match in B' (anti-join) and 'rows in A with at least one match in B' (semi-join) using EXISTS/NOT EXISTS.
Semi-Join: "Has At Least One Match"
Return rows from A that have at least one matching row in B — but only A's columns. SQL implements semi-joins via EXISTS or IN.
EXISTS Semi-Join
Users who have placed at least one order:
SELECT u.* FROM users u
WHERE EXISTS (
SELECT 1 FROM orders o WHERE o.user_id = u.id
);All lessons in this course
- Cross Joins and Cartesian Products
- Lateral Joins (LATERAL JOIN)
- Anti-Joins and Semi-Joins (NOT EXISTS)
- Multi-Table Join Performance Tuning