Set Operations

Union, intersection, difference

About This Calculator

Set theory is the foundation of modern mathematics, providing a language to describe collections of objects and their relationships. Set operations — union, intersection, difference — are used in databases (SQL joins), probability, and logic.

Formula

Union A∪B: all elements in A or B (or both)
Intersection A∩B: elements that are in both A and B
Difference A-B: elements in A but not in B; |A∪B| = |A|+|B|-|A∩B|

Example Calculation

A = {1,2,3,4}, B = {3,4,5,6}

  1. A∪B = {1,2,3,4,5,6}
  2. A∩B = {3,4}
  3. A-B = {1,2}; B-A = {5,6}
Union=6 elements, Intersection=2 elements, A-B=2 elements

Set Operations: A={1,2,3,4}, B={3,4,5,6}

OperationSymbolResultCount
UnionA∪B{1,2,3,4,5,6}6
IntersectionA∩B{3,4}2
Difference A-BA-B{1,2}2
Difference B-AB-A{5,6}2
Symmetric diff.A△B{1,2,5,6}4

Frequently Asked Questions

What is the complement of a set?
The complement of set A (written A') contains all elements in the universal set that are not in A. For example, if U={1,...,10} and A={1,2,3}, then A'={4,5,6,7,8,9,10}.
How do SQL JOINs relate to set operations?
INNER JOIN = intersection (rows in both tables). LEFT JOIN = all rows from left plus matching rows from right. UNION ALL = union of two result sets. Understanding set theory helps with complex database queries.
What is the difference between union and OR in logic?
They are equivalent: A∪B in set theory corresponds to A OR B in propositional logic. An element is in the union if it satisfies condition A or condition B (or both).