I'm trying to pull one record from one table that has a lot of referrences to other tables in it. I would like to be able to pull in the values from the other tables, but I can't do a normal join because multiple fields in the main table reference the same field (but different records) in the other tables.
Like this:
Now the three agents are just reference numbers to another table where the agent info is kept. I do not want what is above, I what something like
pass in T1.AGEone to
(SELECT T2.aName FROM TABLE2 T2, TABLE1 T1
WHERE T1.AGEone = T2.AGEID)
as "Agent 1",
pass in T1.AGEtwo to
(SELECT T2.aName FROM TABLE2 T2, TABLE1 T1
WHERE T1.AGEtwo = T2.AGEID)
as "Agent 2",
pass in T1.AGEthr to
(SELECT T2.aName FROM TABLE2 T2, TABLE1 T1
WHERE T1.AGEthr = T2.AGEID)
as "Agent 3",
This is just an example! The real main table does this a number of times with different tables.
Is there a way to do this???
Thanks for any help!
Judy
Like this:
Code:
SELECT
T1.MainID as "Main ID",
T1.INTREF as "Internal reference",
T1.fileNu as "File",
T1.AGEone as "Agent 1",
T1.AGEtwo as "Agent 2",
T1.AGEthr as "Agent 3"
FROM TABLE1 T1
WHERE T1.IDEBRE = '5'
Code:
SELECT
T1.MainID as "Main ID",
T1.INTREF as "Internal reference",
T1.fileNu as "File",
(SELECT T2.aName FROM TABLE2 T2, TABLE1 T1
WHERE T1.AGEone = T2.AGEID)
as "Agent 1",
pass in T1.AGEtwo to
(SELECT T2.aName FROM TABLE2 T2, TABLE1 T1
WHERE T1.AGEtwo = T2.AGEID)
as "Agent 2",
pass in T1.AGEthr to
(SELECT T2.aName FROM TABLE2 T2, TABLE1 T1
WHERE T1.AGEthr = T2.AGEID)
as "Agent 3",
Code:
FROM TABLE1 T1
WHERE T1.IDEBRE = '5'
This is just an example! The real main table does this a number of times with different tables.
Is there a way to do this???
Thanks for any help!
Judy