In this blog, we are going to see the difference between Union and Union All in SQL with example
"Union All" will not eliminate duplicate rows instead it will pull all the rows.
"Union" removes the duplicate records by issuing "Select Distinct" on the result set.
Union SQL:
select
'1234' Emplid
,'Name1' Name
from Dual
union
select
'1234' Emplid
,'Name1' Name
from Dual
Result:
Union All SQL:
select
'1234' Emplid
,'Name1' Name
from Dual
union all
select
'1234' Emplid
,'Name1' Name
from Dual
Result:
I hope this explains the difference between Union and Union All. If you have any questions, please post it in the comments section.
"Union All" will not eliminate duplicate rows instead it will pull all the rows.
"Union" removes the duplicate records by issuing "Select Distinct" on the result set.
Union SQL:
select
'1234' Emplid
,'Name1' Name
from Dual
union
select
'1234' Emplid
,'Name1' Name
from Dual
Result:
EMPLID
|
NAME
|
1234
|
Name1
|
Union All SQL:
select
'1234' Emplid
,'Name1' Name
from Dual
union all
select
'1234' Emplid
,'Name1' Name
from Dual
Result:
EMPLID
|
NAME
|
1234
|
Name1
|
1234
|
Name1
|
I hope this explains the difference between Union and Union All. If you have any questions, please post it in the comments section.
Comments
Post a Comment