Skip to main content

Command Palette

Search for a command to run...

SQL : UNION Operator

Published
1 min read
SQL : UNION Operator
S

I love learning about technology and sharing that with others

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.

15 views

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)