B
Ben Scaithe
I am trying to figure out the best way to build a query that will list what
I need. I have a single table that has the following fields:
ProductID
IngredientID
IngredientQuantity
IngredientType
There is no Primary Key in this table. The main focus of the table is the
ingredient that makes up the product, so ProductID is repeated in several
rows, as so:
ProductID IngredientID
IngredientQuantity IngredientType
1 100 10
Simple
1 101 3
Simple
1 102 2
Complex
2 101 3
Simple
2 103 7
Complex
102 110 3
Simple
102 111 1
Complex
111 156 4
Simple
111 157 2
Simple
If the IngredientType is "Complex", then it is a product within the product;
it is also listed in the table and has ingredients of its own. For example,
Ingredient 102 is complex, so it is also listed with its own two
ingredients, 110 and 111. Also, 111 is complex as well, and has the
ingredients 156 and 157.
What I need to build is a query that lists the product along with all of the
base ingredients and how much of each. For example, the resulting rows for
Product 1 would look like this:
ProductID IngredientID
IngredientQuantity
1 100 10
1 101 3
1 110 3
1 156 4
1 157 2
Instead of showing 102, it shows its ingredients. Same for 111.
Does anybody know what would be the best way to get the results I need?
Thanks for any help!
I need. I have a single table that has the following fields:
ProductID
IngredientID
IngredientQuantity
IngredientType
There is no Primary Key in this table. The main focus of the table is the
ingredient that makes up the product, so ProductID is repeated in several
rows, as so:
ProductID IngredientID
IngredientQuantity IngredientType
1 100 10
Simple
1 101 3
Simple
1 102 2
Complex
2 101 3
Simple
2 103 7
Complex
102 110 3
Simple
102 111 1
Complex
111 156 4
Simple
111 157 2
Simple
If the IngredientType is "Complex", then it is a product within the product;
it is also listed in the table and has ingredients of its own. For example,
Ingredient 102 is complex, so it is also listed with its own two
ingredients, 110 and 111. Also, 111 is complex as well, and has the
ingredients 156 and 157.
What I need to build is a query that lists the product along with all of the
base ingredients and how much of each. For example, the resulting rows for
Product 1 would look like this:
ProductID IngredientID
IngredientQuantity
1 100 10
1 101 3
1 110 3
1 156 4
1 157 2
Instead of showing 102, it shows its ingredients. Same for 111.
Does anybody know what would be the best way to get the results I need?
Thanks for any help!