Skip to main content
SQL • LESSON 99

NOT EXISTS

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

Advanced3 Minutes1120 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