Management & CommerceVery hardBusiness analyst · MBA placement

customers(id, name) has rows (1, Asha), (2, Ravi), (3, Meena), (4, Kiran). orders(oid, cid, status) has rows (10, 1, 'paid'), (11, 1, 'refunded'), (12, 2, 'paid'), (13, 3, 'refunded'). Query P: SELECT COUNT(*) FROM customers c LEFT JOIN orders o ON c.id = o.cid WHERE o.status = 'paid'. Query Q is the same but with AND o.status = 'paid' moved into the ON clause (no WHERE). What do P and Q return?

  1. A. P = 4, Q = 4
  2. B. P = 2, Q = 4
  3. C. P = 2, Q = 2
  4. D. P = 2, Q = 5

Correct answer: B. P = 2, Q = 4

P filters after the join, discarding the NULL rows of unmatched customers, so it behaves like an inner join: 2 rows. In Q the filter is part of the join condition, so every customer is kept – Asha and Ravi matched, Meena and Kiran with NULLs – giving 4.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic