SQL allows tuples in relations, and correspondingly defines the multiplicity…
2025
SQL allows tuples in relations, and correspondingly defines the multiplicity of tuples in the result of joins. Which one of the following queries always gives the same answer as the nested query shown below : select * from R where a in (select S.a from S)
- A.
select R.* from R, S where R.a=S.a
- B.
select distinct R.* from R,S where R.a=S.a
- C.
select R.* from R, (select distinct a from S) as S1 where R.a=S1.a
- D.
select R.* from R,S where R.a=S.a and is unique R.
Attempted by 59 students.
Show answer & explanation
Correct answer: C
The original query uses IN to find all tuples in R where attribute a exists in S. Option C achieves the same result by joining R with a distinct subset of S values, ensuring correctness while preventing duplicate results.
The DISTINCT keyword in the subquery guarantees that each value from S appears only once, which maintains semantic equivalence with the IN operator.
This approach works because SQL joins produce Cartesian products that are filtered by the WHERE clause, effectively replicating set membership logic.