I am working on advance search functionality, where people able to search recipe using advance search. For that i have these database structures,
1)recipe
id title
1 banana
2 orange
2)filter_main_category
id name
1 ingredients
2 restrictions
3 cuisines
4 meal_type
3)sub_cat
id name
1 bread
2 breakfast
3 dinner
4 banana
5 butter
6 eggs
4)relations
id recipe_id main_category_id sub_cat_id
1 1 4 4
2 1 4 6
3 1 2 6
So, according to table, you can see recipe_id
1 has 3 filters where two with main_category_id
4 and one with main_category_id
2.
Now, if user select main_category_id
= 4 and sub_cat_id = 4,6 in advance search then we have so show that results like this,
SELECT * FROM relations WHERE main_category_id = 4 AND sub_cat_id IN (4,6)
OUTPUT:
id recipe_id main_category_id sub_cat_id
1 1 4 4
2 1 4 6
Now, if user also select main_category_id
= 2 and sub_cat_id
= 6 from advance filter(main_category_id=2 is for restriction, so we have to remove recipe from search result if user select this filter), then we have to remove last record from output(because main_category_id = 2 so we have to restrict sub category from search)
For this what i am trying is,
SELECT * FROM relations WHERE (main_category_id = 4 AND sub_cat_id IN (4,6)) AND ( main_category_id = 2 AND sub_cat_id NOT IN (6) )
But its returning wrong result,
What should i want in output is
id recipe_id main_category_id sub_cat_id
1 1 4 4
Is there any solution to do like this?