Summary: In this chapter, we will learn how to use MySQL UNION operator to combine two or more result sets from multiple SELECT statements into a single result set.
Introducing to MySQL UNION Operator
The UNION operator is used to combine the result-set of two or more SELECT statements.
The syntax of the MySQL UNION is as follows:
SELECT column_name(s) FROM table1 UNION SELECT column_name(s) FROM table2;
NOTE: UNION operator eliminates duplicate rows from the result. while UNION ALL returns duplicate rows also mean result will be same.
MySQL UNION example
Let’s practice with an example of using MySQL UNION to get a better understanding.
First we will create quickly one customers table, In details we will learn later and we have employees table already in our Sample Database.
Suppose we want to combine data from the customers and employees tables into a single result set, we can UNION operator as the following query:
SELECT CustomerId, CustomerName FROM customers UNION SELECT employeeid, firstname FROM employees
Here is the output:

In this chapter, we have learnt how to use MySQL UNION statement to combine data from multiple tables into a single result set.