Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. What is an anti-join?

SQL · Basics & Joins

What is an anti-join?

Mediumsql-08
anti-joinnot existsleft join

Question

What is an anti-join?

Solution

An anti-join finds rows from one table that do not have a match in another table.

Example: customers who never placed an order.

Method 1: NOT EXISTS

SELECT *
FROM customers c
WHERE NOT EXISTS (
    SELECT 1
    FROM orders o
    WHERE o.customer_id = c.id
);

Method 2: LEFT JOIN

SELECT c.*
FROM customers c
LEFT JOIN orders o
    ON c.id = o.customer_id
WHERE o.customer_id IS NULL;

Interview shortcut:

> Anti-join = give me rows that don't have a match.

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext