Hi,
i have the following data in my table called cat_product
cat_id product_id
1 2
1 3
2 2
2 4
If given a set of values for product_id (2,3) i want to know the unique cat_id. In this case, that will be cat_id 1.
how should i construct mysql query?
i tried to use
select distinct cat_id from cat_product where product_id IN (2,3)
but it returns both 1 and 2.
if i use
select distinct cat_id from cat_product where product_id NOT IN (2,3)
i get 2.
is there a better way than
select distinct cat_id from cat_product where product_id IN (2,3)
and cat_id NOT IN
(select distinct cat_id from cat_product where product_id NOT IN (2,3) )
i need to return the category_id that has the EXACT set of product id i am looking for.
basically i have about 10 product ids as input.