UNION deduplicates, while UNION ALL preserves bag multiplicity.
highlighted = computed this step
UNION and UNION ALL differ
UNION deduplicates like a set operation, while UNION ALL keeps bag multiplicity. This is the capstone contrast with Book One set algebra. Note: the two rendered outputs have different cardinalities.
union contrast
UNION deduplicates
The recomputed UNION row count is 3. Note: duplicates are removed by this operator.
union rows=3
SQL bag/multiset + three-valued NULL logic, deterministic but surprising; tiny finite tables; no engine/perf claims. Set algebra is Book 1.
UNION ALL keeps duplicates
The recomputed UNION ALL row count is 5. Note: ALL is the signal to preserve multiplicity.
union all rows=5
SQL bag/multiset + three-valued NULL logic, deterministic but surprising; tiny finite tables; no engine/perf claims. Set algebra is Book 1.
Summary
SQL can move between set-like and bag-preserving behavior depending on the operator. Note: bag and NULL semantics are here; set algebra was Book One.