CS FundamentalsHardGATE 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). What does this query return? SELECT COUNT(*) FROM Bill a JOIN Bill b ON a.amt = b.amt AND a.id <> b.id;

  1. A. 2
  2. B. 4
  3. C. 6
  4. D. 8

Correct answer: B. 4

Equal non-NULL amounts pair bills 1-4 and 3-6, and <> counts each pair in both orders: 4. NULL = NULL is UNKNOWN, so bills 2 and 7 never pair (that mistake gives 6); a.id < b.id would give 2.

More DBMS and SQL questions

Exams that ask this topic