PortMadeleineCrumpet
PortMadeleineCrumpet

Reputation: 115

SQL: In UNION vs UNION ALL, what is the implied ID?

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

Answers (1)

Gordon Linoff
Gordon Linoff

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

Related Questions