Reputation: 115
UNION Vs UNION ALL How does SQL know what to "join on". I realize that this is NOT a join, but there is an ID right for UNION and UNION ALL? Is it the first SELECT item?
That is, if in a UNION query, the overlapped records are not repeated, how does SQL identify the records to leave out?
Upvotes: 1
Views: 197
Reputation: 1269753
There is no "join" with a union. Nor is there a concept of an "id".
The difference between union
and union all
is that union
returns only unique records -- removing duplicates. All columns that participate in the union
are considered as one unit (you may say that all the columns are "keys"). And, for the purposes of uniqueness, NULL
values are considered the same.
Upvotes: 3