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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 join syntax help

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 and
c to d . I tired a query of sort

select * from a inner join b on ....
inner join c on ....,d inner join c

and 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?

Thanks
Kaushik

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
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2002-01-08 : 22:20:02
Kaushik,

What about...

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


DavidM

Tomorrow is the same day as Today was the day before.
Go to Top of Page

spock
Starting Member

35 Posts

Posted - 2002-01-08 : 22:27:55
merkin,
hope this helps

I have an employee table with these fields
employee id
department id
position id

there is a mater table for department
there 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 levels

I 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 ?


Go to Top of Page

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..

DavidM

Tomorrow is the same day as Today was the day before.
Go to Top of Page

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...
Go to Top of Page
   

- Advertisement -