![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I am new to DBs and have started with something simple...a cookbook database. I have a table of 'recipes', with information about the recipe, as well as a key index for each recipe. Next, I have a table of 'ingredients', with information about the ingredient, as well as a key index for reach ingredient. Finally, I have a relationship table, which associates the ingredients with the recipes. It looks something like: Recipe # Ingredient # Quantity 1 14 2 cups 1 22 3 tbsp 2 7 4 lbs etc This is working really well when I just need to get the information about a recipe, a simple "SELECT....WHERE Recipe# = ##" returns all that I need. However, I would like to extend this database so that when I give it a list of 'ingredients', it will show me all 'recipes' I can make with the given ingredients. For instance, in the top table if I have ingredients 10, 14, and 22, it should tell me I can make recipe #1. Is there an easy way to do this with the table setup I currently have? If not, does anyone have a suggestion as to how I can proceed. Sorry if this is a dumb newbie question, but the only solutions I can come up with will take way too much processing time and are entirely inefficient. |
#3
| |||
| |||
|
|
Hodge.Nate (AT) gmail (DOT) com wrote: I am new to DBs and have started with something simple...a cookbook database. I have a table of 'recipes', with information about the recipe, as well as a key index for each recipe. Next, I have a table of 'ingredients', with information about the ingredient, as well as a key index for reach ingredient. Finally, I have a relationship table, which associates the ingredients with the recipes. It looks something like: Recipe # Ingredient # Quantity 1 14 2 cups 1 22 3 tbsp 2 7 4 lbs etc This is working really well when I just need to get the information about a recipe, a simple "SELECT....WHERE Recipe# = ##" returns all that I need. However, I would like to extend this database so that when I give it a list of 'ingredients', it will show me all 'recipes' I can make with the given ingredients. For instance, in the top table if I have ingredients 10, 14, and 22, it should tell me I can make recipe #1. Is there an easy way to do this with the table setup I currently have? If not, does anyone have a suggestion as to how I can proceed. Sorry if this is a dumb newbie question, but the only solutions I can come up with will take way too much processing time and are entirely inefficient. Given your design, it will likely require some procedural code (ie, something outside of straight SQL SELECT) Although Now that I think about it, a counting query might work. Select recipe #, count(*) from relationship where Ingredient # in ( 10, 14, 22 ) order by count(*) ; That should get you on the right path. Another comment befor you go too far on your system. Quantity would be better as two attributes: Quantity NUMBER, UOM CHAR where UOM stands for Unit of Measure. You will need these split if you even need to convert the recipe (for example to double it for a party or halve it for a two person dinner.) HTH, ed |
#4
| |||
| |||
|
|
Recipe # Ingredient # Quantity 1 14 2 cups 1 22 3 tbsp 2 7 4 lbs etc This is working really well when I just need to get the information about a recipe, a simple "SELECT....WHERE Recipe# = ##" returns all that I need. However, I would like to extend this database so that when I give it a list of 'ingredients', it will show me all 'recipes' I can make with the given ingredients. For instance, in the top table if I have ingredients 10, 14, and 22, it should tell me I can make recipe #1. |
#5
| |||
| |||
|
|
Are you suggesting I add a column to my recipe table as 'Ingredient Count'? If so, then that makes sense and I can make it work from there...thank you! |
#6
| |||
| |||
|
|
I use a Pizza-database for my trainings to ask similar questions :-) |
#7
| |||
| |||
|
|
I use a Pizza-database for my trainings to ask similar questions :-) I am suddenly very hungry. |
#8
| |||
| |||
|
|
Frank Swarbrick wrote: I use a Pizza-database for my trainings to ask similar questions :-) I am suddenly very hungry. That's why i do that lab usually before lunch, especially when i know they serve pizza that day :-) And i favour it over my previous version: a cocktail database... Dieter |
![]() |
| Thread Tools | |
| Display Modes | |
| |