I am admittedly somewhat new at writing complex SQL queries, but not new to SQL. I am trying to write a query that creates resultant records from one parent table and multiple (~15) child tables. I am getting results where there are multiple records per key field corresponding to each record in the child tables.
My question is, is this avoidable (based on the details given here)? And if so, how could I do it?
trfix (parent table)
ID (PK)
traccession (UK)
trtranstype
...
...
...
trdistcode
ID (PK)
traccession(UK,FK)
distcode (UK,FK)
distcode-lookup
ID (PK)
distcode (UK,FK)
distcodedescr
trcontractnum
ID (PK)
traccession (FK)
contractnum
trmonitoracr
ID (PK)
traccession (FK)
monitoracr
select distinct
t.traccession,
dc.distrcode,
ludc.discodedescr,
cn.contractnum,
ma.monitoracr
from trfix t,
trdistributioncode dc,
lu_distributioncode ludc,
trcontractnum cn,
trmonitoracr ma
where t.traccession = dc.traccession
and ludc.distributioncode = dc.distributioncode
and t.traccession = cn.traccession
and t.traccession = ma.traccession
order by t.traccession;
Current results_
traccession distcode distcodedesc contractnum monitorac
A000025 1 text1 XYZ
A000025 1 text1 123-1
A000025 23 text2 XYZ
A000025 23 text2 123-2
Edited by: user7459858 on Dec 22, 2009 11:49 AM
Edited by: user7459858 on Dec 22, 2009 12:05 PM
Edited by: user7459858 on Dec 22, 2009 12:05 PM