Union, intersection, and difference operate only on same-schema relations.

highlighted = computed this step

Set operations need matching schemas

Union, intersection, and difference combine whole row sets. They require identical column names in identical order. Note: the validator rejects incompatible schemas instead of guessing.

union compatible schemas\text{union compatible schemas}

Union, intersect, difference

Here the recomputed union row count is 3, the intersect row count is 1, and the difference row count is 1. Note: every row shown comes from same-schema set algebra.

union=3,intersect=1,difference=1\text{union}=3,\quad \text{intersect}=1,\quad \text{difference}=1

set algebra not SQL bag/NULL, tiny finite tables, no product/perf claims

Unionunionarity 2 rows 3LeftSetarity 2 rows 2RightSetarity 2 rows 2
unioncodetagaxbycz
Intersectintersectarity 2 rows 1LeftSetarity 2 rows 2RightSetarity 2 rows 2
intersectcodetagby
Differencedifferencearity 2 rows 1LeftSetarity 2 rows 2RightSetarity 2 rows 2
differencecodetagax

Difference is not symmetric

Reversing the operands changes which row remains. The recomputed reverse difference row count is 1. Note: A minus B asks a different question from B minus A.

reverse difference=1\text{reverse difference}=1

set algebra not SQL bag/NULL, tiny finite tables, no product/perf claims

Reverse differencedifferencearity 2 rows 1RightSetarity 2 rows 2LeftSetarity 2 rows 2
differencecodetagcz

Summary

Set operations compare complete rows under matching schemas, and difference depends on operand order. Note: SQL duplicate-preserving variants and NULL behavior are deferred to the next book.

set operation summary\text{set operation summary}