I am seeking for the difference between Natural and Equi Join when the common column in one table(P) is unique and but NOT unique in other(Q). then which of the rows from other table(Q) will be displayed, question is there because of the common column in not unique in Q, there will be so many rows associated with single same value of that common attribute in Q.
Both operate on ‘=’ comparator. Just the difference that natural join automatically finds out the common columns and apply ‘=’ comparator implicitly.
Say two tables
P(a(unique),b,c) and Q(a(not unique),d)
and if i apply P natural join Q
and P equi join Q
Then which of the rows will be generated in Natural join and which tuples in Equi join.?
means which of the row from table Q (as same value of ‘a’ is associated with many rows in Q but not so in P ) will be displayed..?
Will there be a difference or not..?
The natural join is just a short-hand for the equi-join. The same tuples should be created, when the same columns are used for the comparison.
Database developers tend not to like natural joins. The addition, removal, or renaming of a column in a table can effect existing queries. And, in general, we don’t want to break existing code if we can avoid it.
Personally, I prefer explicit naming conditions on columns among tables. Foreign keys should have the same name as primary keys, so it is clear what they are referring to. I also prefer “identity” or “auto-increment” primary keys for joins. This however is straying from your question. The same tuples should be generated when the natural join is choosing the same columns for the join.