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
 Transact-SQL (2000)
 LEFT OUTER JOIN on a JOIN??

Author  Topic 

johnc
Starting Member

5 Posts

Posted - 2003-03-19 : 21:22:21
Have the following tables:
Policy A, ClientOrganisation B, Company C, AdviserIDs I, Users U

Performing this join ok:
select * from Policy A LEFT OUTER JOIN AdviserIDs I ON A.AdviserID = I.AdviserNo, ClientOrganisation B, Company C where A.ClientID = B.ClientID and B.CompanyID = C.CompanyID and .....

I need to join it onto Users U ON I.UserNo = U.UserNo
Can't see where I can do this

Need to pull the users name out of users on a match with AdviserID which may or may not be in Policy...

Any thoughts???


Just managed to do it by doing this:
select * from Policy A LEFT OUTER JOIN (select ID.AdviserNo, US.realname from AdviserIDs ID, Users US where ID.UserNo = US.UserNo) IU ON A.AdviserID = IU.AdviserNo, ClientOrganisation B, Company C where A.ClientID = B.ClientID and B.CompanyID = C.CompanyID and ...

Seems a bit messy - any neater suggestions would be greatly received.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Thinking is the hardest work there is, which is the probable reason so few engage in it." - Henry Ford


Edited by - johnc on 03/19/2003 21:48:09

SamC
White Water Yakist

3467 Posts

Posted - 2003-03-19 : 22:44:15
Specing the JOINS requires knowing the keys in the tables to join..

Select *
From Policy A
LEFT OUTER JOIN ClientOrganisation B ON b.??? = a.???
LEFT OUTER JOIN Company C on C.???=A.???
LEFT OUTER JOIN AdviserIDS I on I.???= and so on.
------------------
From the description you gave...

SELECT *
FROM
POLICY A
LEFT OUTER JOIN Advisors I ON A.AdviserID = I.AdviserNo
LEFT OUTER JOIN ClientOrganisation B A.ClientID = B.ClientID
LEFT OUTER JOIN Company C ON B.CompanyID = C.CompanyID
LEFT OUTER JOIN Users U ON I.UserNo = U.UserNo
WHERE whatever

Sam

Edited by - SamC on 03/19/2003 22:52:43
Go to Top of Page
   

- Advertisement -