CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ

Table Bill(id, cust, region, amt) rows: (1, 'Kavi', 'E', 300), (2, 'Lata', 'W', NULL), (3, 'Kavi', 'E', 450), (4, 'Mona', 'W', 300), (5, 'Nair', NULL, 200), (6, 'Lata', 'W', 450), (7, 'Mona', 'E', NULL). Table Cust(name, tier) rows: ('Kavi', 'Gold'), ('Lata', 'Silver'), ('Mona', 'Gold'), ('Ravi', 'Silver'). Query P: SELECT COUNT(*) FROM Cust c LEFT JOIN Bill b ON c.name = b.cust AND b.amt > 300; Query Q: SELECT COUNT(*) FROM Cust c LEFT JOIN Bill b ON c.name = b.cust WHERE b.amt > 300; What do P and Q return?

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

Correct answer: D. 4 and 2

In P the filter is part of the join: Kavi and Lata match one row each, Mona and Ravi are padded with NULLs, giving 4. In Q the WHERE removes the NULL-padded rows after the join, leaving only bills 3 and 6.

More DBMS and SQL questions

Exams that ask this topic