The UNION ALL keywords

By default, the UNION keyword excludes duplicate rows. To retain the duplicate values, add the optional keyword ALL, as the following query shows.
Figure 1. Query
SELECT stock_num, manu_code FROM stock
   WHERE unit_price < 25.00
UNION ALL
SELECT stock_num, manu_code FROM items
   WHERE quantity > 3 
   ORDER BY 2
   INTO TEMP stock item;
The query uses the UNION ALL keywords to unite two SELECT statements and adds an INTO TEMP clause after the final SELECT to put the results into a temporary table. It returns the same rows as Figure 1 but also includes duplicate values.
Figure 2. Query result
stock_num manu_code

        9 ANZ
        5 ANZ
        9 ANZ
        5 ANZ
        9 ANZ
       ⋮
        5 NRG
        5 NRG
      103 PRC
      106 PRC
        5 SMT
        5 SMT

Copyright© 2019 HCL Technologies Limited