natural join change table [message #660267] |
Mon, 13 February 2017 20:24 |
|
asliyanage
Messages: 60 Registered: January 2017
|
Member |
|
|
when i am using natural join with two table i can change the table position as below.
1) select *
from DEPARTMENTS natural join locations;
2)select *
from locations natural join DEPARTMENTS;
I need to know is there any differences between above two times?
|
|
|
|
|
|
|
|
Re: natural join change table [message #660289 is a reply to message #660277] |
Tue, 14 February 2017 03:49 |
cookiemonster
Messages: 13925 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
They are the same. The only join type where the table order makes a difference is LEFT and RIGHT OUTER JOIN.
That said - never, ever use natural join. It's one of the dumbest things ever added to SQL.
Try adding a time_updated column to both tables and see what happens.
|
|
|
Re: natural join change table [message #660320 is a reply to message #660289] |
Tue, 14 February 2017 15:41 |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
I am agreeing with cookiemonster. NO developer would ever use a NATURAL JOIN in any production code. It is guaranteed that It will cause a problem in the future. If I had a developer that used a natural join in anything but an adhoc query, the first time would be a warning, the second time would be a termination.
If there was a database setting that I could set to stop them from working I would immediatly turn it on. Lets take an example. We have 2 tables with the following structure
table1(col1, col2,col3)
table2(col1,col4,col5)
A natural join would join them only on col1. Now I need a new column in table1 and I decided that I wanted to call it col4 my natural join immediatly fails. If I had a normal join nothing breaks. NEVER USE NATURAL JOINS.
|
|
|