CS FundamentalsVery hardGATE CS (PYQ pattern)

R(A, B): (1,x), (2,y), (3,z), (4,NULL). S(B, C): (x,10), (x,11), (y,20), (w,30), (NULL,40). How many rows does SELECT * FROM R FULL OUTER JOIN S ON R.B = S.B AND S.C > 10 return, and how many if the condition S.C > 10 is moved from ON into a WHERE clause?

  1. A. 7 and 7
  2. B. 6 and 4
  3. C. 8 and 4
  4. D. 7 and 4

Correct answer: D. 7 and 4

With the condition in ON: matches are (1,x)-(x,11) and (2,y)-(y,20). Unmatched R rows: 3 and 4; unmatched S rows: (x,10), (w,30), (NULL,40). Total 2 + 2 + 3 = 7. In WHERE, the full join (matches (1,x) twice and (2,y) = 3, plus unmatched R 3 and 4, plus S (w,30) and (NULL,40)) is filtered on S.C > 10: rows with C = 11, 20, 30, 40 survive = 4; rows with NULL C are dropped.

More DBMS and SQL questions

Exams that ask this topic