Joins

Difference and Intersection: EXCEPT and INTERSECT

Senior Data Analyst
February 14, 2026
5 min read

The List Comparison

Marketing asked: *"We have a list of all newsletter subscribers and a list of paying customers. How many subscribers are NOT customers? And how many are both?"*

The Quest: Set Operations

SQL has set operations that work like Venn diagrams.

  • **INTERSECT**: Returns rows that appear in BOTH queries.
  • **EXCEPT** (or `MINUS` in Oracle): Returns rows that appear in the first query but NOT in the second.
  • The Implementation: The Syntax

    Who Subscribe But Never Paid?

    SELECT email FROM newsletter_subscribers

    EXCEPT

    SELECT email FROM paying_customers;

    Who Are Both Subscribers AND Customers?

    SELECT email FROM newsletter_subscribers

    INTERSECT

    SELECT email FROM paying_customers;

    The "Oops" Moment

    I forgot that `EXCEPT` is directional. `A EXCEPT B` is different from `B EXCEPT A`.

    **Pro Tip**: Think of `EXCEPT` as "Give me everything from the first set, but remove anything that's also in the second."

    The Victory

    Marketing discovered that 2,000 subscribers had never converted. They launched a targeted discount campaign and saw a 10% conversion uplift. Set operations are perfect for list analysis.

    Your Task for Today

    Use `EXCEPT` to find users who are in Table A but not in Table B. Then, use `INTERSECT` to find users who are in both.

    *Day 46: Introduction to Subqueries.*

    Ready to put your knowledge into practice?

    Join SQL Mastery and learn through interactive exercises.