CS FundamentalsModerateGATE CS (PYQ pattern)

SP(id, s): (1,10), (2,10), (3,10), (4,20), (5,20), (6,30), (7,NULL), (8,NULL). How many rows does SELECT * FROM SP a JOIN SP b ON a.s = b.s return?

  1. A. 4
  2. B. 14
  3. C. 16
  4. D. 13

Correct answer: B. 14

Each row pairs with every row of equal s, including itself: 3 x 3 + 2 x 2 + 1 x 1 = 14; the NULL rows match nothing (NULL = NULL is unknown). Only distinct unordered pairs would be 4.

More DBMS and SQL questions

Exams that ask this topic