ISRO Scientist/Engineer CSE 2018Databases › SQL
ISRO Scientist/Engineer CSE 2018 PYQ: Given relations $\textsf{R(w,x)}$ and $\textsf{S(y,z)},$ the result of SELECT DISTINCT w, x FROM R, S ls…
Given relations $\textsf{R(w,x)}$ and $\textsf{S(y,z)},$ the result of
SELECT DISTINCT w, x
FROM R, S ls guaranteed to be same as $\text{R},$ if
- A$\textsf{R}$ has no duplicates and $\textsf{S}$ is non-emptyCorrect answer
- B$\textsf{R}$ and $\textsf{S}$ have no duplicates
- C$\textsf{S}$ has no duplicates and $\textsf{R}$ is non-empty
- D$\textsf{R}$ and $\textsf{S}$ have the same number of tuples
Answer
(A) $\textsf{R}$ has no duplicates and $\textsf{S}$ is non-empty
Approach
The query performs a Cartesian product R × S and then projects onto R's attributes (w, x), removing duplicates via DISTINCT. We need the result to equal R exactly. Since projection of R × S onto (w, x) yields each tuple of R repeated |S| times (once per tuple of S), DISTINCT collapses these repetitions back to the original tuples of R. Thus the result equals R precisely when R has no duplicates (so DISTINCT doesn't remove any of R's own tuples) and S is non-empty (so every tuple of R actually appears at least once).
Reviewed by ISRO IQ Editorial Team.