Learn SQL/Advanced/Interview Patterns/SQL Anti-Join Pattern

SQL Anti-Join Pattern

The formal name for 'rows in A with no match in B' — everything from the last two lessons, named properly.

What & Why

An anti-join returns rows from one table that have no corresponding match in another. It's not a distinct SQL keyword — it's the name for the pattern you get from NOT EXISTS or LEFT JOIN ... WHERE NULL.

See How It Works

BUSINESS QUESTION

Product wants features that have never received feedback.

idnamedescriptionteamreleased_atdeprecated_at
1Activation ChecklistGuides new users through setupgrowth2024-01-20NULL
2CSV ExportExports report dataplatform2024-02-14NULL
3Invite NudgesPrompts workspace collaborationgrowth2024-03-05NULL
4Legacy DashboardOriginal reporting surfaceanalytics2023-08-102024-06-01
iduser_idfeature_idratingnps_scorecommentcreated_at
1101159Clear and useful2024-01-25 12:15:00+00
210224NULLExport worked well2024-02-20 15:40:00+00
3103147Helpful setup flow2024-03-18 09:05:00+00
410433NULLNeeds clearer timing2024-04-08 17:30:00+00
Watch NOT EXISTS keep the feature with no feedbackStep 1 of 4
NOT EXISTS product.feedback where feedback.feature_id = feature.id
feature_idfeaturefeedback_idsdecision
1Activation Checklist1, 3SKIP
2CSV Export2SKIP
3Invite Nudges4SKIP
4Legacy DashboardKEEP

Activation Checklist has two feedback rows.

EXAMPLE QUERY
SELECT
  f.id AS feature_id,
  f.name
FROM product.features f
WHERE NOT EXISTS (
  SELECT 1
  FROM product.feedback fb
  WHERE fb.feature_id = f.id
)
ORDER BY feature_id;

This lesson's practice is part of Pro.

Advanced business practice

Sign up free to try it on a real business scenario