Hello everyone.
I was hoping someone could help me understand outer joins better.
I have the following tables set up :
FormulaTable:
I am trying to query these tables so that I get all items from a formula, and if any of the ingredients have “ACID” associated with them in the IngredGroup table, I want that to show. So for this data it would look like:
I put in the following query:
Code:
SELECT FormulaTable.FormulaName, FormulaTable.[Item#], FormulaTable.Ingredient, IngredGroup.Group
FROM FormulaTable LEFT JOIN (IngredTable RIGHT JOIN (GroupTable RIGHT JOIN IngredGroup ON
GroupTable.Group = IngredGroup.Group) ON IngredTable.Ingred = IngredGroup.Ingred) ON
FormulaTable.Ingredient = IngredGroup.Ingred
WHERE (((FormulaTable.FormulaName)=[X]) AND ((IngredGroup.Group)=[Y]));
If I enter F1 and ACID for the variables, I get this:
If I add:
OR (((FormulaTable.FormulaName)=[X]) AND ((IngredGroup.Group) Is Null)) to WHERE, I get:
So I’m still missing RM4 since it is tagged with “INORG” but not “ACID”. I guess I understand that part, since RM4 is not null. However I thought that with the outer joins I used, I would get everything with FormulaName = “F1”, but it seems to be behaving more like an inner join.
Where have I gone wrong? Any quick suggestions on how to get the output I intended?
Thank you for your time!