I have 2 tables :
Ingredients with the following fields:
ID(numeric) Ingredient(text) Plural(text)
where Ingredient is the name of the ingredient and Plural is its plural name(ex:olive,olives)
and another table Shopping_Ingredients with the fields:
Amount(numeric) , Ingredient_ID(numeric)
I need a SQL statement that returns the added value of Amount for all the table Shopping_Ingredients and the Ingredient name (singular when it doesn’t have plural or plural when it does)
example :
Ingredients :
1 ‘apple’ ‘apples’
2 ‘garlic’ ”
Shopping_Ingredients:
1 1
2 1
3 1
2 2
3 2
return :
6 ‘apples’
5 ‘garlic’
Since You didn’t specify what database engine You use, here is version of query that works on SQL Server 2000 and newer (probably works on MySQL also):
And here for SQL Server 2005 and newer: