I have a table with the following schema in MySQL
Recipe_Quantity_ID,Recipe_ID, Recipe_Quantity, Ingredients_ID, Ingredient_Measurement_ID
The sample data can be found in this SQL Fiddle http://sqlfiddle.com/#!2/d05fe .
I want to search the table for the given (one or many) Ingredients_ID and return the Recipe_ID that has this Ingredients_ID
I do this by using this SQL
select Recipe_ID
from recipe_quantity
group by Recipe_ID
having count(*) = {$ar_rows}
and sum(Ingredients_ID in ({$ids})) = {$ar_rows}
which may translate to
select Recipe_ID
from recipe_quantity
group by Recipe_ID
having count(*) = 4
and sum(Ingredients_ID in (8,5,45,88)) = 4
For searching for less Ingredients_ID I substract the last ID until I reach one Ingredient ID. By using this technique of course is not possible to search for all the combinations. Eg 8,5,45,85 | 8,45,85 | 45,85 | 5,45,85 etc.
Any ideas how I can search for all the combinations that may be true? Thanks in advance.