Beginner

653. SEMI JOIN

Understand the pattern for returning rows when at least one related record exists.

📘 Lesson 653 of 728 ⏱ 14 min 🎯 Advanced

A Semi JOIN returns rows from one table when a matching row exists in another table without returning columns from the matching table.

It is useful when you only need to test whether a relationship exists.

Find customers who have placed at least one order.

SQL
SELECT
    c.CustomerID,
    c.CustomerName
FROM Customers c
WHERE EXISTS (
    SELECT 1
    FROM Orders o
    WHERE o.CustomerID = c.CustomerID
);

Used in customer activity, eligibility checks, transaction validation, and existence testing.

  • EXISTS is a common Semi JOIN pattern.
  • Only rows from the main table are returned.
  • The matching table is used only for existence testing.
  • Multiple matching rows do not duplicate the outer row.
  • Useful when related columns are not required.
What is a Semi JOIN?

It returns rows from one table when at least one matching row exists in another table.

Why use EXISTS instead of a regular JOIN?

EXISTS checks relationship existence without multiplying the outer rows when multiple matches exist.

Have you finished this lesson?

Introduction to SQL – All Lessons