Ah I see the problem now!
I don't know if Atli's suggestion works, but I did something like this a while back in another context.
-
SELECT count(*) as rowcount, d.drinkid, d.drinkname
-
FROM tDrinks AS d
-
INNER JOIN tDrinkIngredients AS i
-
ON d.drinkid = i.drinkid
-
AND i.ingredientid IN (63,211)
-
GROUP BY d.drinkid HAVING rowcount = 2
-
The above might work (haven't tested it for syntax errors and logic errors).
The idea is this: Since your one to many relationship in the join (a drink has many ingredients) will give you multiple rows for the same drinkid if there are more than one ingredient match, you need to do a GROUP BY.
Then you just add this count(*) as rowcount attribute to your query. With the Group by clause, it will give you the count of how many rows have been grouped for each drink.
If only one ingredient matched, rowcount for that drink is 1. If two ingredients matched, then rowcount will be 2.
In your situation, you want all the drinks that match ALL the ingredients that you have selected. So you want only the rows in your results that have rowcount equal to the number of drinks. Hence, you use the HAVING rowcount = 2 here.
To make this flexible for all user selections, you of course need to substitute the IN clause with the list of ingredients that were actually selected, and you need to substitute the value of 2 in the "HAVING rowcount = 2" with the number of ingredients that were selected.
Or did I misunderstand the problem yet once again? :)