CS FundamentalsHardGATE CS (PYQ pattern)

Tables D(d): 1, 2, 3, 4. E(e, d, sal): (10,1,60), (11,1,40), (12,2,30), (13,3,70), (14,3,80), (15,NULL,90). How many rows does SELECT * FROM D LEFT JOIN E ON D.d = E.d AND E.sal > 50 return?

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

Correct answer: C. 5

The sal > 50 test is part of the join condition, so unmatched D rows are still kept with NULLs: d=1 matches (10), d=2 none, d=3 matches 13 and 14, d=4 none = 5 rows. Putting the test in WHERE would give 3; no test gives 6.

More DBMS and SQL questions

Exams that ask this topic