Skip to main content
SQL โ€ข LESSON 98

EXISTS

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

Advancedโฑ 3 Minutesโญ 1110 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