The below are the differences between Union and Union ALL .
S.No |
Union |
UnionAll |
1 |
This
is used to eliminate duplicate rows |
It
will not eliminate duplicate rows |
2 |
t
can be used to combine any number of queries |
It
can be used to combine maximum of 2 queries |
3 |
It
cannot contain aggregate functions |
It
can contain aggregate functions |
4 | Union is slower than UnionAll | UnionAll is faster than Union |
5 |
Output
is in sorted order Example : SELECT Col FROM @Table1 UNION SELECT Col FROM @Table2 Result: 1 2 3 5 |
Output is not in sorted order Example : SELECT Col FROM @Table1 UNION ALL SELECT Col FROM @Table2 Result: 1 2 3 2 5 |
No comments:
Post a Comment