一个简单,但不是很好弄的sql语句
某个产品属于两个category,比如产品101即属于类3又属于类5.
现在要从中选出不在类4,类5的产品.如何剔除101呢.
表products_to_categories
products_id categories_id
101 3
101 5
202 4
表products
products_id
101
102
103
104
我用语句
select p.products_id from products p,products_to_categories p2c where p.products_id=p2c.categories_id and p2c.categories_id not in(4,5)
目标是剔除产品101,但还是会选出101,因为它虽然属于类5,但也属于类3.
所以上面的语句没办法实现.