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 |
|
spock
Starting Member
35 Posts |
Posted - 2002-01-08 : 22:08:43
|
| Hi,I have 4 tables a,b,c,d i want to inner join a to b , a to c andc to d . I tired a query of sortselect * from a inner join b on .... inner join c on ....,d inner join cand it was not working . without giving table d another reference like d d_duplicate and then inner joining it to c is there any other way it can be done?ThanksKaushik |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2002-01-08 : 22:11:41
|
| You haven't made yourself very clear...Can you give us more idea of what your tables are ? DDL would be best.What you are trying to do doesn't sound hard, it's just you havent given enough info.Damian |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2002-01-08 : 22:20:02
|
Kaushik,What about...Select * from Ainner join B on B.ID = A.IDinner join C on C.ID = A.IDinner join D on D.ID = C.ID DavidMTomorrow is the same day as Today was the day before. |
 |
|
|
spock
Starting Member
35 Posts |
Posted - 2002-01-08 : 22:27:55
|
| merkin,hope this helps I have an employee table with these fieldsemployee iddepartment idposition idthere is a mater table for departmentthere is a table which captures the relationship between position id , post type and organisational level.and there are separate master tables for post types,organisational levelsI need to get an employees name,dept name,organisation level,positon type and position type name i want to inner join employee table to department and relationship table and then i want to inner join the relationship table to postion type master tables.David,Thanks , i found out that it worked perfectly but when i specify the third inner join which table am i joining it to? i thought i was joining D to A and so it would'nt work but it works.could you please clarify ? |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2002-01-08 : 22:35:55
|
| Kaushik,The initial table in the FROM clause has no special relevance to any proceeding INNER JOIN statement unless specified..DavidMTomorrow is the same day as Today was the day before. |
 |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2002-01-08 : 23:00:30
|
| Kaushik,If it makes it clearer for you, bracket your inner joins.Select * from (((A inner join B on B.ID = A.ID) inner join C on C.ID = A.ID) inner join D on D.ID = C.ID)Some people prefer this as it reinforces that each join is on the result of the previous one.However, once you're clear in your head what's happening, DavidM's format is nice and clean.mad dogs and englishmen... |
 |
|
|
|
|
|
|
|