Mark As Completed Discussion

UNION ALL

As mentioned above, UNION and UNION ALL are pretty similar, with the main difference being in how they treat any possible duplicate values in the resulting set. That means that when using the UNION ALL operator, all duplicate values are included in the final result.

In order to better see the difference between these two operators, let us take a look at the query and resulting table shown below.

TEXT/X-SQL
1SELECT * FROM Table1
2UNION ALL
3SELECT * FROM Table2;

Result:

UNION ALL

In this example, we can see that the rows with customer IDs 2 and 3 are contained twice, which means that the UNION ALL operator accepts duplicates in its final result.