var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Select a field if mathes to 2 or more criteria
I have this db table
I want the query to search for a product that belongs to 2 categories (having the cat_id's). In this case search for products that belongs to cat_id's 1 and 2.
in this example is prod_id=1 (belongs both to 1 and 2).
Is this possible to be done with a query ??
from ur_table a
where exists (select 1 from ur_table b
where a.prod_id <> b.prod_id
and a.cat_id = b.cat_id)
I'm not sure the previous query will work (apologies if it does). Anyway something like the following might work better and be easier to expand if you need to match against 3 categories etc:
where cat_id in ( 1,2 )
group by prod_id
having count( distinct cat_id ) = 2;
Thanks a lot guys
I used Mike's solution and it works !!