Following on from my query yesterday, I’ve restructured my recipe database as follows:
categories
cid | category_name
1 | desserts
2 | cakes
3 | biscuits
recipes
id | recipe_name
1 | black forest cake
2 | angel cake
3 | melting moments
4 | croquembouche
5 | crepes suzette
ingredients
iid | ingredient_name
1 | self-raising flour
2 | milk
3 | chocolate
4 | baking powder
5 | plain flour
6 | eggs
recipe_categories
recipe_id | category_id
1 | 1
4 | 1
5 | 1
1 | 2
2 | 2
3 | 3
4 | 3
recipe_ingredients
recipe_id | ingredient_id
1 | 1
2 | 1
4 | 1
1 | 2
2 | 2
3 | 2
5 | 2
1 | 3
2 | 3
1 | 4
3 | 5
4 | 5
My query needs to return recipes by category with ingredients listed using
to separate the ingredients (possibly using GROUP_CONCAT(i.ingredient_name separator ‘
‘) output as suggested yesterday).
So, a query for desserts would output:
black forest cake:
self-raising flour
milk
chocolate
croquembouche:
self-raising flour
plain flour
crepes suzette:
milk
plain flour
I know I have to join recipe_ingredients and recipes and ingredients and search categories, but I’m really struggling on how to do this.
Query:
Result:
Here is what you asked for using the GROUP_CONCAT. Each ingredient is seperated by
,