0PricingLogin
SQL Academy · Lesson

UNION, INTERSECT, EXCEPT

Combine compatible result sets with UNION, find common rows with INTERSECT, and find the difference with EXCEPT.

Set Operations Overview

Three set operators combine result sets row-by-row:

  • UNION — rows in A OR B (deduplicated)
  • INTERSECT — rows in A AND B
  • EXCEPT — rows in A but NOT in B

UNION

Combine two result sets, removing duplicates:

SELECT email FROM users
UNION
SELECT email FROM newsletter_subscribers;

All lessons in this course

  1. UNION, INTERSECT, EXCEPT
  2. UNION ALL vs UNION (Deduplication Cost)
  3. CASE Expressions and Pivot Queries
  4. Crosstab Patterns (PostgreSQL crosstab())
← Back to SQL Academy