The UNION operator is used to find the result-set or combination of two or more tables.
Terms and Condition for using UNION:
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
The UNION operator selects only distinct values by default. To allow duplicate values, use UNION ALL:
SELECT column_name(s) FROM table1
UNION ALL
SELECT column_name(s) FROM table2;
Select *
from Employee1;
ID | Name | Salary |
---|---|---|
1234 | Divya | 1000 |
2345 | Anshu | 2000 |
3456 | Kalia | 3000 |
Select *
from Employee2;
ID | Name | Salary | City |
---|---|---|---|
5678 | Pradeep | 26000 | gurgaon |
7890 | Mahesh | 24500 | Noida |
7900 | Raju | 25600 | Delhi |
SELECT Name, Salary, City FROM Employee1
UNION ALL
SELECT Name, Salary, City FROM Employee2;