Skip to main contentSkip to solution

What is the difference between UNION and UNION ALL?

Solution

✅ Correct Option: 2

UNION combines the result sets of two SELECT statements and removes duplicate rows from the combined result. UNION ALL combines them and keeps every row, including duplicates.

Because UNION ALL skips the duplicate-removal step, it is usually faster.


Option 1: both operators stack rows from the two queries. Joins are what add columns side by side.

Option 3: this reverses the two operators.

Option 4: set difference is done with EXCEPT (or MINUS), and the cartesian product comes from CROSS JOIN. Neither is done by UNION or UNION ALL.

Both operators need the same number of columns, with compatible data types, in the two queries.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question