I have a query like:
SELECT coc.title, inc.name FROM cocktail coc, ingredients inc WHERE coc.id = 1...
This query is just an short example
And the result is:
Title: Cuba Libre, Ingredient Name: Cola
Title: Cuba Libre, Ingredient Name: Rum
Title: Cuba Libre, Ingredient Name: Limette
I get 3 times the title because this cocktail has 3 incredients.
If I use the result set like this I get 3 times the title as the headline.
But I want:
Title: Cuba Libre, Ingredient Name: Cola
Ingredient Name: Rum
Ingredient Name: Lime
I would like to have just one time the title and all ingredients in my result set.
I there any possibility to do this in one query or do I have to execute another request afterwards just for the ingredients?
If you want the items in the same row, then you can use
GROUP_CONCAT():see SQL Fiddle with demo