Management & CommerceVery hardBusiness analytics · SQL · MBA placement

cust has rows (1, Asha), (2, Ravi), (3, Meena). ord(oid, cid, status) has (10, 1, 'paid'), (11, 1, 'due'), (12, 2, 'due'). How many rows does each query return? P: SELECT c.name, o.oid FROM cust c LEFT JOIN ord o ON c.id = o.cid AND o.status = 'paid'; Q: SELECT c.name, o.oid FROM cust c LEFT JOIN ord o ON c.id = o.cid WHERE o.status = 'paid';

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

Correct answer: C. P = 3, Q = 1

In P the filter is part of the join, so every customer is kept: Asha with order 10, and Ravi and Meena with NULLs (3 rows). In Q the WHERE runs after the join and removes rows whose status is NULL or 'due', leaving only Asha's order 10, which silently turns the left join into an inner join.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic