CS FundamentalsHardTCS Digital · Infosys SP · GATE CS

Table Product(pid, cat, price) rows: (1, 'X', 10), (2, 'X', 20), (3, 'Y', 20), (4, NULL, 30), (5, 'Y', NULL), (6, 'Z', 5). What does this query return?

Table Product(pid, cat, price) rows: (1, 'X', 10), (2, 'X', 20), (3, 'Y', 20), (4, NULL, 30), (5, 'Y', NULL), (6, 'Z', 5). What does this query return?
SELECT COUNT(*) FROM Product
WHERE price BETWEEN 10 AND 20
   OR cat IN ('Z', NULL);
  1. A. 5
  2. B. 4
  3. C. 3
  4. D. 6

Correct answer: B. 4

BETWEEN is inclusive: pids 1, 2, 3 match. cat IN ('Z', NULL) is TRUE for pid 6 (cat = 'Z'); for other rows it is FALSE or UNKNOWN. Total 4.

More DBMS and SQL questions

Exams that ask this topic