CS FundamentalsVery hardGATE CS

A(x) = (3, 5, NULL, 8, 9, 12) and B(x) = (4, NULL, 6). How many rows does SELECT x FROM A WHERE x > ALL (SELECT x FROM B) return? (ALL is true only if the comparison is TRUE for every row of the subquery; one UNKNOWN comparison makes the result not TRUE.)

  1. A. 0
  2. B. 3
  3. C. 1
  4. D. 2

Correct answer: A. 0

B contains a NULL, so for every x the comparison with that row is UNKNOWN and x > ALL can never be TRUE: the result is 0 rows. Ignoring the NULL (largest non-NULL value 6) would wrongly return the 3 rows 8, 9 and 12.

More DBMS and SQL questions

Exams that ask this topic