SQL & Queries

Answer & solution
Official answer: C
1. Set up the reasoning. IN is an existence test: a matching R occurrence survives once irrespective of how many matching S rows exist. Reproduce that effect by deduplicating only S's join-key values before joining.
2. Derive the result. IN tests membership, preserving each original occurrence of an R row once when at least one matching nonnull S.a exists. Joining to SELECT DISTINCT a FROM S creates exactly one matching S1 row per such value, preserving R’s multiplicities: C. A multiplies rows when S repeats a; B removes duplicate R rows. SQL null comparisons remain nontrue in both the IN filter and equality join, so nulls do not invalidate C.
3. Check the interpretation. A can multiply an R occurrence by duplicate S keys; B can erase distinct occurrences of the same R tuple. C keeps R's bag multiplicity while giving one matching right-side row. NULL does not satisfy either filter's equality test, so it does not break the equivalence.