SoonerToucan
Programmer
I am having trouble with the following query.
Important Tables:
Product (table of products)
--ProductID
--ProductName
ProductCategories (Associates a Product with one or more categories)
--ProductID
--CategoryID
Category (table of categories that a product may fall under)
--CategoryID
--CategoryName
Information:
Basically I have a product that falls into two categories. Therefore there are two records in the ProcuctCategories Table. I am trying to create a query that will find all products that are in categories A & B.
Attempted Solution:
SELECT * FROM Product
WHERE (ProductID IN (SELECT CategoryID FROM ProductCategories WHERE CategoryID =A))
AND
(ProductID IN (SELECT CategoryID FROM ProductCategories WHERE CategoryID =B))
This returned zero records though it should have returned the product that is in categorys A&B.
I would appreciate any help available.
Thank you,
-Patrick
Important Tables:
Product (table of products)
--ProductID
--ProductName
ProductCategories (Associates a Product with one or more categories)
--ProductID
--CategoryID
Category (table of categories that a product may fall under)
--CategoryID
--CategoryName
Information:
Basically I have a product that falls into two categories. Therefore there are two records in the ProcuctCategories Table. I am trying to create a query that will find all products that are in categories A & B.
Attempted Solution:
SELECT * FROM Product
WHERE (ProductID IN (SELECT CategoryID FROM ProductCategories WHERE CategoryID =A))
AND
(ProductID IN (SELECT CategoryID FROM ProductCategories WHERE CategoryID =B))
This returned zero records though it should have returned the product that is in categorys A&B.
I would appreciate any help available.
Thank you,
-Patrick