Sorry if that title didn’t explain it well.
Here is the table…

(source: alexanderdickson.com)
I want to select product_id where it is in either 5 or 6 but not if it is in 7.
Maybe I’ve lost the plot, but I came up with this query
SELECT `product_id` , `category_id`
FROM `wp_wpsc_item_category_assoc`
WHERE (
`category_id` =5
OR `category_id` =6
)
AND `category_id` !=7
LIMIT 0 , 30
Except obviously because of the many to many relationship this will still return a record where category_id is 7, in this case the product with a product_id of 12.
How can I change this query to get all products with either a category_id of 5 or 6, but not if it is also a part of 7.
Thanks guys.
Update
Thanks for all your answers. My daily vote limit is reached, so I’ll come back tomorrow and vote up the useful answers.
We use a subquery to do the exclusion for each particular product_id.