Answer: Union:
1.UNION only selects distinct values
2.Output is in sorted order
UnionAll:
1.UNION ALL selects all values (including duplicates).
2.Output is not in sorted order
EX:
SELECT Col
FROM @Table1
UNION
SELECT Col
FROM @Table2
/* Result of Union All operation */
SELECT Col
FROM @Table1
UNION ALL
SELECT Col
FROM @Table2
Output:
Union:
1
2
3
5
UnionAll:
1
2
3
2
5
Asked In: Many Interviews |
Alert Moderator