Or even better
Main Topics
Browse All TopicsI'm struggling on how to extract a list by joining multiple tables without getting alot of duplicate values.
In the example below the IV00101 table is the items master with one entry for each item.
The second table has multiple entries for each item so I only want the match item and whose RCRDTYPE=1.
The remaiing tables typically have fewer items than in the master in one case is joined based on the iv00102 table.
What I'm looking for a result is one line per item in the item master and the results in the select as statements.
What am I doing wrong with my select and join?
Thanks
SELECT iv1.itemnmbr AS 'ItemNumber'
,iv1.itemdesc AS 'ItemDescription'
--,iv1.itmshnam 'ItemShortName'
,iv3.planningleadtime as 'LeadTime'
, HM5.HM_Currency_1 AS 'ListPrice'
,iv3.vnditnum 'VendorNumber'
,pm2.vendname AS 'VendorName'
,(case when ev6.pricegroup like '%SALE%' then 'Yes'
else 'No' end
) as 'OnSale'
FROM iv00101 iv1
JOIN iv00102 iv2 ON iv2.ITEMNMBR = iv1.ITEMNMBR and iv2..RCRDTYPE=1
Left JOIN iv00103 iv3 ON iv3.itemnmbr = iv1.ITEMNMBR
Left JOIN eiv00600 ev6 ON ev6.itemnmbr = iv1.ITEMNMBR
Left JOIN hm00500 hm5 ON hm5.itemnmbr = iv1.ITEMNMBR
Left JOIN pm00200 pm2 ON pm2.VENDORID = iv2.PRIMVNDR
Left join bm10300 bm1 on bm1.itemnmbr = iv1.ITEMNMBR
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I was still getting some duplicates so I updated the statement but am now receiving errors. The main change was for IV00103 which also has multiple items and ties back to iv00102 on the PRIMVNDR field.
The errors are:
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "iv2.primvndr" could not be bound.
Msg 207, Level 16, State 1, Line 16
Invalid column name 'PRIMVNDR'.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'planningleadtime'.
Msg 207, Level 16, State 1, Line 6
Invalid column name 'vnditnum'.
The updated select is:
SELECT iv1.itemnmbr AS 'ItemNumber'
,iv1.itemdesc AS 'ItemDescription'
--,iv1.itmshnam 'ItemShortName'
,iv3.planningleadtime as 'LeadTime'
, HM5.HM_Currency_1 AS 'ListPrice'
,iv3.vnditnum 'VendorNumber'
,pm2.vendname AS 'VendorName'
,(case when ev6.pricegroup like '%SALE%' then 'Yes'
else 'No' end
) as 'OnSale'
FROM iv00101 iv1
JOIN (select distinct ITEMNMBR from iv00102 where RCRDTYPE = 1) iv2 ON iv2.ITEMNMBR = iv1.ITEMNMBR
left JOIN (select distinct itemnmbr from iv00103 where vendorid=iv2.primvndr) iv3 ON iv3.itemnmbr = iv1.ITEMNMBR
Left JOIN eiv00600 ev6 ON ev6.itemnmbr = iv1.ITEMNMBR
Left JOIN hm00500 hm5 ON hm5.itemnmbr = iv1.ITEMNMBR
Left JOIN pm00200 pm2 ON pm2.VENDORID = iv2.PRIMVNDR
Left join bm10300 bm1 on bm1.itemnmbr = iv1.ITEMNMBR
Business Accounts
Answer for Membership
by: ralmadaPosted on 2009-10-15 at 10:45:28ID: 25582888
Try like this:
Select allOpen in new window