TriAdX Posted January 16, 2007 Share Posted January 16, 2007 I have 3 tables..Category, Product and Product_Categorythe product_category table is a 2 colum table with cat_id and Product_id which is used to link products to the catsI want to be able to pull ALL cat_ids that do NOT have a product in them...this could occur a few different ways:category with an entry in product_category table but no product in the product tablecategory with NO entries AT ALL in the product_category.I need 2 queries.. one that pulls all cats with NO entry in the product_category tableand one that pulls all cats with and entry in the product_category table but NO product existing in the product table..someone please help Link to comment Share on other sites More sharing options...
xpriens Posted January 22, 2007 Share Posted January 22, 2007 Hi,for the Query, with "that pulls all cats with and entry in the product_category table but NO product existing in the product table.." u can use the followig SQL Statement....Select * from Category C join Products_Category PC on C.CategoryId=PC.CategoryId left outer join Products P on PC.ProductId=P.ProductIdwhere P.ProductId is Nullfor the second half, with "one that pulls all cats with NO entry in the product_category table"Select * from Category C left outer join Products_Category PC on C.CategoryId=PC.CategoryId where PC.CategoryId is Null hope this helps and solves ur problem.... I have 3 tables..Category, Product and Product_Categorythe product_category table is a 2 colum table with cat_id and Product_id which is used to link products to the catsI want to be able to pull ALL cat_ids that do NOT have a product in them...this could occur a few different ways:category with an entry in product_category table but no product in the product tablecategory with NO entries AT ALL in the product_category.I need 2 queries.. one that pulls all cats with NO entry in the product_category tableand one that pulls all cats with and entry in the product_category table but NO product existing in the product table..someone please help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now