Home

UNION should be used with caution

Rule description

  • UNION should be used with caution

 

Non-compliant Code Example

SELECT Name, Phone FROM Employee
UNION                                       --Non compliant code (Use UNION ALL instead of Union)
SELECT Name, Phone From Customer;
SELECT Name, Phone FROM Customer WHERE StateCode=0015
UNION                                       --Non compliant code (No need to use Union clause, get entries by changing Where clause)
SELECT Name, Phone From Customer WHERE StateCode=0028;

Compliant Code Example

SELECT Name, Phone FROM Employee
UNION ALL                                      --Compliant code (UNION ALL is used)
SELECT Name, Phone From Customer;
SELECT Name, Phone 
From Customer 
WHERE StateCode=0028 OR StateCode=0015;       --Compliant code
Visual Expert 2020
 VEPLSQLRULE165