Semijoins, Antijoins, and Existential Filters
Preserve an outer row based on existence of a match and avoid accidental multiplicity changes or null-sensitive comparisons.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
A matching partner is a yes-or-no witness
A semijoin returns left rows that have a partner, emitting each left occurrence once even if several partners qualify. An antijoin retains those with none. This can be expressed by existence tests on the matching predicate. Joining and projecting can instead repeat a left row once per partner, and DISTINCT can remove duplicates that already belonged to the left input.
Missing values matter to the chosen expression
Using a negated membership comparison can differ from a correlated nonexistence test when the result includes a missing value. Ordinary SQL equality with that value is UNKNOWN. Define the desired missing-value behavior explicitly when matching keys. Three-valued logic explains the comparison. Bag semantics explains why a semijoin’s output multiplicity is intentionally different from an ordinary join’s.[1][2]