0PricingLogin
SQL Academy · Lesson

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

  1. Cross Joins and Cartesian Products
  2. Lateral Joins (LATERAL JOIN)
  3. Anti-Joins and Semi-Joins (NOT EXISTS)
  4. Multi-Table Join Performance Tuning
← Back to SQL Academy