Skip to main content
SQL • LESSON 98

EXISTS

How can we find customers who have at least one order?

Advanced3 Minutes1110 XP
🤔 THE QUESTION

How can we find customers who have at least one order?

💡 WHAT IS IT?

EXISTS tests for the existence of rows in a correlated subquery, returning true as soon as one match is found.

🎯 WHAT IS IT USED FOR?

High-performance presence checks, finding active purchasing customers, transactional auditing.

💻 EXAMPLE
SELECT c.customer_name
FROM customers c
WHERE EXISTS (
    SELECT 1
    FROM orders o
    WHERE o.customer_id = c.customer_id
);

🎯 Mission Objectives

Practice typing production-grade SQL code for EXISTS.

  • EXISTS operator
  • Correlated subquery
  • Short-circuit optimization
  • Customer activity check