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 2008 Forums
 Transact-SQL (2008)
 join 3 tables very complicated in sqlserver

Author  Topic 

nagiub2007
Starting Member

1 Post

Posted - 2012-04-08 : 19:15:49
i have 3 tables (employee,structure,District)
1_employee empid,workid fk to structid ,actuallwork fk to struct id 2_ structure structid , districtId fk to district 3_District districtid , districtname

i want to get

empid , work , actuallwork

i want under work and actualwork district name

ahmed naguib

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-09 : 00:33:42
use two separate joins


SELECT d1.districtname as work,
d2.districtname as actualwork
FROM employee e
inner join structure s1
on s1.structid = e.workid
inner join district d1
on d1.districtid = s1.districtid
inner join structure s2
on s2.structid = e.actualwork
inner join district d2
on d2.districtid = s2.districtid


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -