Management & CommerceVery hardBusiness analyst · KPO · MBA placement pattern

Table orders(order_id, customer, region, amount) has 7 rows: (1, Asha, North, 500); (2, Ravi, South, 300); (3, Asha, North, 200); (4, Meena, East, NULL); (5, Ravi, South, 700); (6, John, North, 400); (7, Meena, East, 350). Table customers(name, tier) has 4 rows: (Asha, Gold), (Ravi, Silver), (Kiran, Gold), (John, Bronze). What does SELECT c.name, COUNT(o.order_id) FROM customers c LEFT JOIN orders o ON c.name = o.customer GROUP BY c.name; return?

  1. A. 4 rows, with Kiran showing 0
  2. B. 5 rows, including Meena with 2
  3. C. 3 rows; Kiran does not appear
  4. D. 4 rows, with Kiran showing 1

Correct answer: A. 4 rows, with Kiran showing 0

A LEFT JOIN keeps every customer. Kiran has no orders, so the joined row has NULL order_id, and COUNT(o.order_id) gives 0 (COUNT(*) would wrongly give 1). Meena is not in customers, so she does not appear. Result: Asha 2, Ravi 2, Kiran 0, John 1.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic