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). Table Cust(name, tier) rows: ('Kavi', 'Gold'), ('Lata', 'Silver'), ('Mona', 'Gold'), ('Ravi', 'Silver'). How many rows does this query return? SELECT region FROM Bill UNION SELECT tier FROM Cust;

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

Correct answer: B. 5

UNION removes duplicates and treats all NULLs as one value, so the result is {E, W, NULL, Gold, Silver} = 5 rows. UNION ALL would keep all 11; ignoring the NULL row gives 4.

More DBMS and SQL questions

Exams that ask this topic