Share
UNION Example
Look at the following tables:
"Employees_Bali":
| E_ID | E_Name |
| 01 | Putu Sanjaya |
| 02 | Made Sanjaya |
| 03 | Haru Sanjaya |
| 04 | Ketut Sanjaya |
"Employees_Lombok":
| E_ID | E_Name |
| 01 | Lalu Selamet |
| 02 | Mamiq Djumenah |
| 03 | Haru Sanjaya |
| 04 | Amaq Sadikin |
Now we want to list all the different employees in Bali and Lombok.
We use the following SELECT statement:
SELECT E_Name FROM Employees_Norway
UNION
SELECT E_Name FROM Employees_USA
The result-set will look like this:
E_Name
Putu Sanjaya
Made Sanjaya
Haru Sanjaya
Ketut Sanjaya
Lalu Selamet
Mamiq Djumenah
Amaq Sadikin
Note: This command cannot be used to list all employees in Bali and Lombok. In the example above we have two employees with equal names, and only one of them will be listed. The UNION command selects only distinct values.