Reputation: 625
What if 2 columns have the same name in a natural join of 2 tables? Which tuples will be selected, is it enough if one column value is the same or does it require both columns then
Upvotes: 2
Views: 2592
Reputation: 97848
Table1 NATURAL JOIN Table2
is equivalent to
Table1 JOIN Table2
ON Table1.Col1 = Table2.Col1
AND Table1.Col2 = Table2.Col2
...
with all column names which exist in both tables being added to the ON clause.
So yes, since it is an AND not an OR which is implied, they must all match.
This is useful if you have a 2-part Key, e.g. company_code
+ username
, and a hazard if you have standard named non-key fields, such as date_created
.
Upvotes: 5