Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help with SQL statement

Author  Topic 

kifeda
Posting Yak Master

136 Posts

Posted - 2010-06-08 : 16:17:39
I have a table tblproductsOptions that contains elements of the product options including the labelid and the value of the option, strvalue. This has 13 records. I have another table called tblproductAssociation that contains the association between the primary product and the auxiliary products. This has four recods,all of which associate the auxiallary products to the primary product. (So another words all four of those records have to do with the primary product) When I do a left outer join on the tblproductsAssociation I get more than 13 records. This is because the table tblproductAssociation has four records in it but I just want to get the intassociatedProductsId value located in the tblproductAssociation.

Here is my query:

select po.intproductid pa.intpfrom tblproductOptions po left outer join tblproductAssociations pa on pa.intproductid = po.intproductid

I want to get

just the 13 original records from the productOptions table PLUS the associated ID number from the associatedProducts table. Instead what I get is 60 records back. How do I use distinct to get rid f the extra records? I tried:

select distinct (po.intproductid, pa.intassociatedProductid) from tblproductOptions po left outer join tblproductAssociations pa on pa.intproductid = po.intproductid

but this errored

Any thoughts?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-09 : 02:14:25
Some sample data and wanted output would be more clear.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -