Skip to main content
SQL โ€ข LESSON 99

NOT EXISTS

How can we find customers who have never placed an order?

Advancedโฑ 3 Minutesโญ 1120 XP
๐Ÿค” THE QUESTION

How can we find customers who have never placed an order?

๐Ÿ’ก WHAT IS IT?

NOT EXISTS returns true when the correlated subquery returns zero matching rows.

๐ŸŽฏ WHAT IS IT USED FOR?

Inactive customer targeting, zero-transaction auditing, missing reference detection.

๐Ÿ’ป EXAMPLE
SELECT c.customer_name
FROM customers c
WHERE NOT EXISTS (
    SELECT 1
    FROM orders o
    WHERE o.customer_id = c.customer_id
);

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for NOT EXISTS.

  • โœ“ NOT EXISTS
  • โœ“ Correlated exclusion
  • โœ“ Inactive user discovery
  • โœ“ Anti-pattern query