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
 join multiple tables

Author  Topic 

adonweb
Starting Member

4 Posts

Posted - 2010-06-19 : 09:26:50
i have 3 tables namely:
departments, divisions, secretary

departments
---------------------------
id,
departmentname,
divisionid,
secretaryid

Divisions
---------------------------
id,
divisionname

Secretary
--------------------------
id,
name
departmentid


i need to show the result in the following format.

departmentname divisionname secretaryname
=============== =============== =================
dept1 div1 sec1
dept2 div2
dept3 div1 sec2
dept4 div2 sec2
dept5 div1 sec1

how can i write a query to produce the above result. I m using ms access



SD_Monkey
Starting Member

38 Posts

Posted - 2010-06-19 : 23:11:30
[code]
Select b.departmentname,a.divisionname,c.name
from Divisions a
inner join
(departments b inner join Secretary c on b.secretaryid on c.id)
on a.id=b.divisionid
[/code]

hope this can help...


A maze make you much more better
Go to Top of Page
   

- Advertisement -