In my MySQL database I have the following tables:
recipes (=ricette) which contains the id of the recipe and some basic info
ingredients (=ingredienti) which as got as many rows as many ingredients there are in that recipe, and finally the table
recipe_kind (=tiporicetta) which contains the id of the recipe and the kind of the recipe.
I would like to get all the ingredients of a recipe and so I perform:
SELECT DISTINCT
r.nome,
r.descrizione,
r.persone,
t.tipo,
c.cibo,
i.quantita,
i.unitamisura_id
FROM
ricette AS r
LEFT JOIN
ingredienti AS i ON i.ricette_id = r.id
LEFT JOIN
cibo AS c ON c.id = i.cibo_id
LEFT JOIN
tiporicetta AS t ON t.id = r.tiporicetta_id
WHERE
(r.id = '52')
but with that query I get the name, description, people and kind many times, once for each row. Instead, I would like to have nome, descrizione, persone and tipo only once and then the list of the ingredients. How can I do that with an unique query?
GROUP BY, withgroup_concat.