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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Complex SQL

Author  Topic 

dazzjazz
Starting Member

2 Posts

Posted - 2002-12-17 : 23:38:05
Hi,

As my DB has a many-to-many relationship, I'm having trouble
extracting DISTINCT records.
The following SQL is retrieving the correct number of records, however, I
now need to add fields from a table
that is linked via the many to many relationship.

The desired result is to get each productID only once.

Query1 = "SELECT productID,productName,isNew,description,imagePathThumb,"
Query1 = Query1 & " dateCreate,isOnSpecial,isOnSpecialPrice,price"
Query1 = Query1 & " FROM tblProducts"
Query1 = Query1 & " INNER JOIN tblManufacturers ON
tblManufacturers.manufacturerId = tblProducts.manufacturerId"
Query1 = Query1 & " WHERE productID IN (SELECT DISTINCT productsId FROM
tblProducts_SubCat)"
Query1 = Query1 & " AND tblProducts.isNew=1"
Query1 = Query1 & " ORDER BY productName"
****************************************************************************
******

Some info on my table structure:

tblProducts_SubCat stores a productID, mainCategoryID, subCategoryId from
tblProducts, tblMainCategory and tblSubCategory respectively.
That is to say that 1 Product can be assigned multiple Main Categories and
SubCategories.

I expect I need to another inner join, something like:

INNER JOIN tblProducts_SubCat ON tblMainCategory.mainCategoryId =
tblProducts_SubCat.mainCatID

but I keep getting syntax errors

Very Complex for me. I'd appreciate some help

Darren

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-12-17 : 23:39:52
Please don't cross-post:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=22420

Go to Top of Page
   

- Advertisement -