SQL UnionJanuary 2, 2023 2023-01-02 6:10
UNION operator is used to combine the result-set of two or more
UNIONmust have the same number of columns.
- The columns must also have similar data types.
- The columns in every
SELECTstatement must also be in the same order.
The above figure shows two tables, Student and Employee, we can combine the two tables using UNION operator as follows.
SELECT FirstName, LastName, Age FROM EMPLOYEE UNION SELECT FirstName, LastName, Age FROM STUDENT
NOTE: Union will create the distinct of the duplicate values between two tables, and the result will be as follows