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.
| 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. |
 |
|
|
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? |
 |
|
|
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 name2) Order will depends on common columnFor example,Patient Table columns are: Pat_id, name..............Room Table columns are: Room_id, description, floor etcPatientRoom Table columns are: id, patient_id, Room_idSELECT ......FROM PatientRoom pr --------------------------------- Rel1JOIN Room r ON pr.id = r.Room_id -------------------- Rel2JOIN Patient p ON pr.patien_id = p.pat_id ------------ Rel3But you can't change it toSELECT ......FROM Patient p ------------------------------------- Rel3JOIN Room r ----------------------------------------- Rel2PatientRoom pr -------------------------------------- Rel1The reason is the Patient and Room tables have no common column....--Chandu |
 |
|
|
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. |
 |
|
|
|
|
|
|
|