SQL Union


SQL Union

The UNION operator is used to combine the result-set of two or more SELECT statements.

  1. Every SELECT statement within UNION must have the same number of columns.
  2. The columns must also have similar data types.
  3. The columns in every SELECT statement 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
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

Please comment and share if you like this post and tell us about how we can enhance our posts. Thanks.