UNION, INTERSECT & EXCEPT · Question 6 · Easy

UNION, INTERSECT & EXCEPT question 6

Two queries are known to have no rows in common, and neither has duplicates. Why is UNION ALL usually preferred over UNION for combining them?

  1. UNION ALL sorts the rows and UNION does not
  2. UNION cannot combine more than two queries
  3. UNION ALL skips the duplicate-removal step, so it does less work for the same result
  4. UNION ALL allows different column counts
Answer and explanation

Answer: C. UNION ALL skips the duplicate-removal step, so it does less work for the same result

Explanation: UNION has to compare the rows (by sorting or hashing) to remove duplicates. When there are no duplicates to remove, UNION ALL gives the same rows without that extra cost.

Previous: Which condition must two SELECT statements satisfy before they can be combined… · Next: A query is written as SELECT emp_name FROM Staff UNION SELECT trainee_name…

Practise union, intersect & except

Try a fresh set of union, intersect & except questions with an explanation after every answer, free and without signing up: UNION, INTERSECT & EXCEPT practice. Or sit a full placement mock test.

More union, intersect & except questions

More sql practice

Tables, Keys & Constraints · DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling

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