Join with 1 table but join with another if there's a fail
Posted: Wed Jun 20, 2007 4:59 am
I have 4 tables in total, the first two (A & B) will always join. I'm looking for a statement that will join A & B and then try and join those to C but if no records are returned then try and join to table D.
So far I have the statement:
But this makes the query hang for a long time although it wouldn't be returning more than a few hundred records.
Am I structuring my statement wrong or is this not possible in 1 single query?
So far I have the statement:
Code: Select all
SELECT A.*, B.*, c.FirstName, c.Surname, c.CompanyName, D.name, D.compName
FROM A as A, B as B, C as C, D as D
WHERE A.uid = B.id
AND A.accmngr = 'name'
AND (A.sageCode = C.cs3
OR A.sageCode = D.cs3)
Am I structuring my statement wrong or is this not possible in 1 single query?