Management & CommerceHardBusiness analyst · SQL test

cust(id, name) has rows (1, Asha), (2, Ravi), (3, Meena), (4, Kiran), (5, Dev). ord(oid, cid, amt, dt) has rows (1, 1, 500, 2 Jan), (2, 1, 300, 5 Jan), (3, 3, 200, 3 Jan), (4, 3, 200, 3 Jan), (5, 5, 900, 4 Jan), (6, 1, 100, 9 Jan). Which names does SELECT c.name FROM cust c LEFT JOIN ord o ON c.id = o.cid WHERE o.oid IS NULL return?

  1. A. Asha, Meena and Dev
  2. B. Ravi and Kiran
  3. C. No rows
  4. D. Ravi, Kiran and Dev

Correct answer: B. Ravi and Kiran

The LEFT JOIN keeps every customer; customers with no order get NULLs in the ord columns. Filtering WHERE o.oid IS NULL keeps exactly those – Ravi (2) and Kiran (4). This 'anti-join' finds customers who never ordered.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic