This Is Not Homework. I have changed the names of the tables and fields, for illustrative purposes only. I admit that I am completely new to MySQL. Please consider that in your answer.
The best way to illustrate the function of the query I need is like this:
I have two tables.
One table has a 0..1 to 0..n relationship to the other table.
For Simplicities Sake Only, Suppose that the two tables were Recipe and Ingredient.
One of the fields in the Ingredient table refers to the Recipe table, but may be null.
Just For Example:
I want to know the SQL for something like: How many recipes call for "Olives" in the amount of "1" AND "Mushrooms" in the amount of "2"
Being brand new to The Structured Query Language, I'm not even sure what to google for this information.
Am I on the right track with the following?:
SELECT COUNT(DISTINCT Recipe.ID) AS Answer FROM Recipe, Ingredient
WHERE Ingredient.RecipeID=Recipe.ID AND Ingredient.Name='Olives'
AND Ingredient.Amount=1 AND Ingredient.Name='Mushrooms'
AND Ingredient.Amount=2
I realize this is totally wrong because Name cannot be BOTH Olives And Mushrooms... but don't know what to put instead, since I need to count all recipes with both, but only all recipes with both.
How can I properly write such a query for MySQL?