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? (|| is standard string concatenation; in MySQL's default mode it means OR.) SELECT COUNT(DISTINCT region || cust) FROM Bill;

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

Correct answer: A. 4

Concatenating with a NULL gives NULL, so Nair's row yields NULL and COUNT(DISTINCT ...) ignores it. The distinct non-NULL strings are EKavi, WLata, WMona and EMona: 4.

More DBMS and SQL questions

Exams that ask this topic