CS FundamentalsVery hardGATE CS

P(g, v) = (a, 5), (a, 7), (a, 7), (b, 3), (b, NULL), (b, 9), (c, 4), (c, 4), (d, NULL), (NULL, 1), (NULL, 2). How many rows does SELECT * FROM P x JOIN P y ON x.g = y.g AND x.v < y.v return?

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

Correct answer: D. 3

Rows join only within equal non-NULL g, and the comparison v < v is UNKNOWN whenever either v is NULL, so NULLs never match. Counting pairs in each group gives 3; with <= the identical rows would also pair, giving 14.

More DBMS and SQL questions

Exams that ask this topic