AP 25 - Use UNION ALL instead of UNION

Severity

Warning Caution

Type

Performance

Problem

UNION is used to return the unique result across two tables.

This is not only unnecessary in most cases, but it could also lead to wrong results. Also, using UNION instead of UNION ALL by accident can have a big impact on performance.

Solution

Use UNION ALL instead of UNION

Legitimate use of the anti pattern

The UNION operator is what you need if you want to get rid of duplicate records in two different data sets.