pro_id | Category
--------+---------
25 | electronics
27 | Electrical
25 | household
27 | electronics
25 | industrial
Above is my database table. I want to filter the results by category. If “electronics” is the selected category, the results should include product ids 25 and 27. This is easy. But I want to filter by multiple categories. For example if I select “electronics” and “household”, the result should be only product id 25.
See example here: http://sqlfiddle.com/#!2/09028/7
Join your table to itself by pro_id, then filter by categories to select all product having both categories:
Select all product having at least one category: