Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 natural join order

Author  Topic 

query12
Starting Member

6 Posts

Posted - 2012-10-10 : 10:55:33
Hi,

What's the reason for choosing Rel1 natural join Rel2 natural join ... natural join Reln over Reln natural join Reln-1 natural join ... natural join Rel1 ? The final result is still the same, only the column order seems to differ.

Thanks.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-10-10 : 11:06:39
As you stated, only the column order would differ. Since SQLTeam is a Microsoft SQL Server website and SQL Server doesn't support natural join, there's not much else we can offer.
Go to Top of Page

query12
Starting Member

6 Posts

Posted - 2012-10-11 : 03:12:49
Ok, what if it's a join on the columns with identical names? Say each 2 relations have one (unique on the set of all possible pairs of relationsm) common column. Then would the order matter?
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-11 : 03:32:46
quote:
Originally posted by query12

Ok, what if it's a join on the columns with identical names? Say each 2 relations have one (unique on the set of all possible pairs of relationsm) common column. Then would the order matter?



In SQL Server,

1) INNER JOIN (or) JOIN keyword is used to combine result set based on common column name

2) Order will depends on common column

For example,
Patient Table columns are: Pat_id, name..............
Room Table columns are: Room_id, description, floor etc
PatientRoom Table columns are: id, patient_id, Room_id

SELECT ......
FROM PatientRoom pr --------------------------------- Rel1
JOIN Room r ON pr.id = r.Room_id -------------------- Rel2
JOIN Patient p ON pr.patien_id = p.pat_id ------------ Rel3


But you can't change it to

SELECT ......
FROM Patient p ------------------------------------- Rel3
JOIN Room r ----------------------------------------- Rel2
PatientRoom pr -------------------------------------- Rel1


The reason is the Patient and Room tables have no common column....


--
Chandu
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-10-11 : 07:16:42
quote:
Ok, what if it's a join on the columns with identical names?
For a natural join, that is implied and required. Duplicate column names are automatically removed from the SELECT list. All other join types have to specify the columns to be joined.
Go to Top of Page
   

- Advertisement -