SQL · Question 15 · Hard

Table A has one column x with rows: 1, 1, 2, NULL Table B has one column x with rows: 1, 1, NULL, 3 What does this query return?

SELECT COUNT(*)
FROM (SELECT x FROM A
      UNION
      SELECT x FROM B) t;
  1. 5
  2. 4
  3. 8
  4. 3
Answer and explanation

Answer: B. 4

Explanation: UNION removes duplicates, and for duplicate elimination two NULLs count as the same value. The distinct values are 1, 2, 3 and NULL, so the count is 4. UNION ALL would give 8.

Previous: Table A has one column x with rows: 1, 1, 2, NULL Table B has one column x… · Next: Which keyword is written after SELECT to remove duplicate rows from a query's…

Practise sql

Try a fresh set of sql questions with an explanation after every answer, free and without signing up: SQL practice. Or sit a full placement mock test.

More sql questions

More technical & programming practice

Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps · GenAI Basics · Pseudo-code · C Programming · Java

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge