CS FundamentalsHardGATE CS

R(x) = (1, 2, 2, 3, NULL, NULL, 5), S(x) = (2, 3, 3, NULL, 6), T(x) = (2, 2, 3, NULL, 5, 7) (one column each). How many rows does (SELECT x FROM R UNION ALL SELECT x FROM S) INTERSECT (SELECT x FROM T) return? (INTERSECT removes duplicates and treats NULLs as equal.)

  1. A. 4
  2. B. 6
  3. C. 5
  4. D. 2

Correct answer: A. 4

The UNION ALL has all 12 values; INTERSECT with T keeps each distinct value present on both sides once. Values 2, 3 and NULL are common, but 5 also appears in both (R has 5, T has 5): the result has 4 rows. Treating NULL as unequal would lose one row.

More DBMS and SQL questions

Exams that ask this topic