Subject SQL Question
Author Daniel R. Jimenez
Hi,

I seem to be having a serious mental breakdown as I am not able to come up
with an efficient way to complete a query.

I have two tables, call it Master and Detail.

Master has fields:
M_ID (PK)
M_Description

Detail has fields:
D_ID (PK)
D_M_ID_1 (FK)
D_M_ID_2 (FK)
D_M_ID_3 (FK)
D_M_ID_4 (FK)

The FK fields in the Detail may point to any master record. Thus they may
all point to the same record.

I would like to retrieve all record from the Detail table where D_M_ID_1 =
:Parameter So the sql could be something like:

SELECT *
FROM
DETAIL
INNER JOIN
MASTER
ON
DETAIL.D_M_ID_1 = MASTER.M_ID
WHERE
DETAIL.D_M_ID_1 = :PARAMETER



This may come back with tow records such as:

D_ID | D_M_ID_1 | D_M_ID_2 | D_M_ID_3 | D_M_ID_4
1 | 2 | 3 | 4 | 2
2 | 3 | 7 | 5 | 9



But rather than displaying the retrieved FK (M_ID) data for each and every
FK, I will like to display the M_Description data associated to the retried
FK, so it would look like

D_ID | D_M_ID_1 | D_M_ID_2 | D_M_ID_3 | D_M_ID_4
1 | desc_2 | desc_3 | desc_4 | desc_2
2 | desc_3 | desc_7 | desc_5 | desc_9


Thank you for the help

daniel