SQL : UNION Operator

What is UNION Operator

  • Union Operator is basically used to combine multiple result set of multiple Select Statements

Below SQL will show us the city from both the table, but it will not show the duplicate city values.


select city from employee
UNION
select city from department;

UNION ALL

  • This will show the duplicate values also
select city from employee
UNION ALL
select city from department;

Example: UNION with where clause.

select city, country from employee
where country='germany'
select city,country from department
where country='germany'
order by city;

above SQL will give city and country with the country as Germany and it will order it by city in ascending order.