SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 natural join order
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

query12
Starting Member

6 Posts

Posted - 10/10/2012 :  10:55:33  Show Profile  Reply with Quote
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.

Edited by - query12 on 10/10/2012 10:56:05

robvolk
Most Valuable Yak

USA
15636 Posts

Posted - 10/10/2012 :  11:06:39  Show Profile  Visit robvolk's Homepage  Reply with Quote
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 - 10/11/2012 :  03:12:49  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2170 Posts

Posted - 10/11/2012 :  03:32:46  Show Profile  Reply with Quote
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

USA
15636 Posts

Posted - 10/11/2012 :  07:16:42  Show Profile  Visit robvolk's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000