What is the difference between UNION and UNION ALL in Oracle SQL?

1 Answers
Answered by suresh

Difference between UNION and UNION ALL in Oracle SQL - Oracle Interview Question

Difference between UNION and UNION ALL in Oracle SQL

UNION and UNION ALL are both used to combine the result sets of two or more SELECT statements in Oracle SQL, but they have a key difference:

  • UNION: UNION removes duplicate records from the combined result set. If the same record appears in multiple SELECT statements being combined, it will only appear once in the final result set.
  • UNION ALL: UNION ALL does not remove duplicate records. It simply combines the result sets of the SELECT statements without eliminating duplicates.

It's important to note that because UNION ALL does not remove duplicates, it is generally faster than UNION since it does not need to perform the additional step of identifying and removing duplicates.

When deciding between using UNION and UNION ALL in Oracle SQL, consider whether you want to include or exclude duplicate records in the final result set.

Answer for Question: What is the difference between UNION and UNION ALL in Oracle SQL?