I'm trying to get this query to return a list of product IDs, descriptions, and all of each product's ingredients. The query shown executes fine but returns only one record - the first product ID in the table, its corresponding description, and every ingredient in the ingredients table. The ingredients returned are grouped properly and in the right order, but they are all concatenated into one result. Example:
Product1 has ingredients A1, B1, C1 Product2 has ingredients A2, B2, C2, D2
And the result of the current query is:
[Product1_ID], [Product1_Description], "A1,B1,C1,A2,B2,C2,D2"
What I want is:
[Product1_ID], [Product1_Description], "A1,B1,C1" [Product2_ID], [Product2_Description], "A2,B2,C2,D2"
Am I going about this the right way? Here is my query:
SELECT TPD.intProductID AS ProductID,
TD.strDescription AS Description,
GROUP_CONCAT( TRH.strName SEPARATOR ', ' ) AS Ingredients
FROM TProductsDescriptions AS TPD,
TDescriptions AS TD,
TRawHerbs AS TRH,
TProductsIngredients AS TPI
WHERE TPD.intDescriptionID=TD.intDescriptionID
AND TPD.intProductID=TPI.intProductID
AND TPI.intIngredientID=TRH.intRawHerbID;