Management & CommerceVery hardBusiness analyst · SQL test

cust has Asha (1), Ravi (2) and Meena (3); ord has orders 10 and 11 for customer 1 and order 12 for customer 3. A report uses SELECT c.name, COUNT(*), COUNT(o.oid) FROM cust c LEFT JOIN ord o ON c.id = o.cid GROUP BY c.id. What does it show for Ravi?

  1. A. COUNT(*) = 0 and COUNT(o.oid) = 0
  2. B. COUNT(*) = 1 and COUNT(o.oid) = 0
  3. C. Ravi does not appear
  4. D. COUNT(*) = 1 and COUNT(o.oid) = 1

Correct answer: B. COUNT(*) = 1 and COUNT(o.oid) = 0

The LEFT JOIN keeps Ravi with one row of NULLs. COUNT(*) counts that row (1), but COUNT(o.oid) skips NULLs (0). Using COUNT(*) here would wrongly show Ravi as having one order.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic