Skip to content
Advertisement

Get suppliers that doesn’t belong to a category in another table

I’m looking for a query where I need to show all the Suppliers from the Suppliers table that doesn’t have products from category 1 (Products.CategoryID = 1). Whenever I run it it always gives an error.

table views

Side question: How do I get these results but with suppliers that has products from cat. 6 ? (So none from cat1 but does have from cat6).

Advertisement

Answer

Rather than using sub-selects, try to use set based operations like joins or exists. One option for your situation is below, though there are several ways to achieve what you are looking to do. Which one is best will depend on your data:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement