Set Theory Basics Cheat Sheet

Set theory fundamentals — union, intersection, complement, Venn diagrams, cardinality, power sets, and set notation for discrete math and data science.

Last Updated: July 15, 2025

Core Operations

OperationNotationMeaningSQL Equivalent
UnionA ∪ BElements in A or B (or both)UNION / UNION ALL
IntersectionA ∩ BElements in both A and BINNER JOIN / INTERSECT
DifferenceA − BElements in A but not BLEFT JOIN WHERE B IS NULL / EXCEPT
ComplementA' or AᶜElements not in ANOT IN (subquery)
Symmetric DiffA △ BIn A or B but not both(A − B) ∪ (B − A)

Set Relationships

RelationNotationMeaning
SubsetA ⊆ BEvery element of A is in B
Proper SubsetA ⊂ BA ⊆ B and A ≠ B
SupersetA ⊇ BA contains all elements of B
DisjointA ∩ B = ∅No elements in common
EqualA = BA ⊆ B and B ⊆ A

Cardinality Rules

FormulaDescription
|A ∪ B| = |A| + |B| − |A ∩ B|Inclusion-Exclusion (2 sets)
|A ∪ B ∪ C| = |A|+|B|+|C| − |A∩B|−|B∩C|−|A∩C| + |A∩B∩C|Inclusion-Exclusion (3 sets)
|A × B| = |A| × |B|Cartesian product cardinality
|P(A)| = 2^|A|Power set — all subsets of A

Common Sets

SymbolSetExamples
Natural numbers{1, 2, 3, ...} or {0, 1, 2, ...}
Integers{..., −2, −1, 0, 1, 2, ...}
Rational numbersp/q where p,q ∈ ℤ, q ≠ 0
Real numbersAll points on number line
Empty setSet with no elements — |∅| = 0
Pro Tip: Every SQL JOIN is a set operation: INNER JOIN = intersection, LEFT JOIN = A ∪ (A ∩ B), FULL OUTER JOIN = union. Understanding sets makes SQL intuitive.
Part of the Empire Builder Network