Join Jumble
Hi! I have a one-to-many query problem that crops up for me when I try to return unique values that may have multiple records on a joined table.
I have a db with 3 tables.
INVOICE
sys_record_num (unique on this table)
inv_num
inv_amt
inv_pay_date
po_num
PART_DETAIL
sys_record_num (may recur on this table)
part_num
part_desc
PURCH_ORDER
po_num
po_type
My query looks like:
SELECT
t1.sys_record_num,
t1.inv_num,
t1.po_num,
t2.part_num,
t2.part_desc,
t3.po_type
FROM
invoice t1,
part_detail t2,
purch_order t3
WHERE
t1.sys_record_num = t2.sys_record_num and
t1.po_num = t3.po_num and
t3.po_type = âmaterialâ
In this one (t1) to many (t2) query, Iâm trying to pull a data set in which each row is a record of the invoice with part information, and where there are mutliple parts in t2 for a given sys_record_num in t1, there will be multiple lines in the data set.
Instead, when I execute this query I get a data set with one sys_record_num value and one inv_num value, both repeating down the entire set, and part_num and part_desc values changing row to row. For example:
sys_record_num inv_num part_num part_desc po_type
1235 55657 Ak112 repositor material
1235 55657 991kk1 magmon material
1235 55657 boiloff material
1235 55657 11AA2 tooling material
1235 55657 99af991 assy kit material
1235 55657 MRIdrive7 materialâ¦etc
In my DB, there is only one part record on t2 where sys_record_num = 1235 and inv_num = 55657. I'm just not sure why the query is repeating the sys_record_num and inv_num values for each row. Its should be moving to the next record.
I know I just need a different kind of join relationship here, but have no idea how to express it properly.
Thank you in advance for any help you can offer.[/size=6]
|