July 27, 2009 at 10:53 am
There is a table A which has certain fields that point to the primary keys of different tables. While joining the tables, some of the columns for certain rows might contain null instead of a value.
If there are 5 rows in table x, after joining the other tables, there should always be 5 rows.
There is a table A and other tables B,C,D,E
Assume the data in A is as follows:
ColA ColB ColC ColD ColE
1 2 3 4 5
1 null 6 null null
1 7 null 8 null
1 null null null 9
The colB corresponds to primary col of table B, colC to primary col of table C, cold to primary col of table D and cole to primary col of table E
I need a query which would return the same 4 rows and the names instead of reference key values of the fields representing the primary key of the other tables.
July 27, 2009 at 11:12 am
if you could provide the actual table definitions, you could get a more refined answer.
basically what you want to do is LEFT join all the tables, so you get either a NULL description or the actual description if the key in TABLEA finds a match.
SELECT
TABLEA.*
TABLEB.DESCRIP
TABLEC.DESCRIP
TABLED.DESCRIP
TABLEE.DESCRIP
FROM TABLEA
LEFT OUTER JOIN TABLEB ON TABLEA.BID = TABLEB.BID
LEFT OUTER JOIN TABLEC ON TABLEA.CID = TABLEB.CID
LEFT OUTER JOIN TABLED ON TABLEA.DID = TABLEB.DID
LEFT OUTER JOIN TABLEE ON TABLEA.EID = TABLEB.EID
Lowell
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply