CS FundamentalsHardProduct-company placement

Cust(cid, city) has rows (1, 'Pune'), (2, 'Delhi'), (3, NULL), (4, 'Pune'). What are the values of Q1: SELECT COUNT(*) FROM (SELECT city FROM Cust UNION SELECT city FROM Cust) t; Q2: SELECT COUNT(DISTINCT city) FROM Cust;

  1. A. Q1 = 2, Q2 = 2
  2. B. Q1 = 4, Q2 = 2
  3. C. Q1 = 3, Q2 = 3
  4. D. Q1 = 3, Q2 = 2

Correct answer: D. Q1 = 3, Q2 = 2

UNION removes duplicates and treats NULLs as duplicates of each other, leaving Pune, Delhi and NULL: 3 rows. COUNT(DISTINCT city) ignores NULL entirely, so it gives 2.

More DBMS and SQL questions

Exams that ask this topic