Skip to content

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

  1. A
    $\textsf{R}$ has no duplicates and $\textsf{S}$ is non-empty
    Correct answer
  2. B
    $\textsf{R}$ and $\textsf{S}$ have no duplicates
  3. C
    $\textsf{S}$ has no duplicates and $\textsf{R}$ is non-empty
  4. 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.