Management & CommerceHardBusiness analyst · SQL test

prod(pid, name) has Pen (1), Book (2) and Bag (3); sales(pid, qty) has rows (1, 5), (1, 3), (2, 4). How many rows do these return? P: SELECT p.name FROM prod p JOIN sales s ON p.pid = s.pid; Q: SELECT name FROM prod WHERE pid IN (SELECT pid FROM sales).

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

Correct answer: D. P = 3, Q = 2

The join repeats Pen once per matching sales row (2) plus Book (1) = 3 rows. IN only tests membership, so each product appears at most once: Pen and Book = 2. Use IN or EXISTS when you want the list of products, not the sales rows.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic