CS FundamentalsVery hardGATE CS · Amazon/Microsoft SDE MCQ

Table Bill(id, cust, region, amt) rows: (1, 'Kavi', 'E', 300), (2, 'Lata', 'W', NULL), (3, 'Kavi', 'E', 450), (4, 'Mona', 'W', 300), (5, 'Nair', NULL, 200), (6, 'Lata', 'W', 450), (7, 'Mona', 'E', NULL). In standard SQL (SQLite lacks ALL; the result was checked with the equivalent NOT EXISTS form), what does this return? SELECT COUNT(*) FROM Bill WHERE amt > ALL (SELECT amt FROM Bill WHERE region = 'X');

  1. A. 0
  2. B. 5
  3. C. 7
  4. D. 6

Correct answer: C. 7

No row has region 'X', so the subquery is empty, and a comparison with ALL over an empty set is TRUE for every row, even rows whose amt is NULL. All 7 rows are counted.

More DBMS and SQL questions

Exams that ask this topic