0
I have two tables: Produtos
, Eventos
and Productsprovents(coming from the many ratio for many of the tables Products and Events):
I performed the following SQL to get the event data and products present in this event, and got the following result:
SELECT p.nome, e.titulo, e.descricao, e.obs, e.cupom, e.inicio, e.fim
FROM ((eventos e INNER JOIN
ProdutosEventos pe ON e.idevento = pe.idevento) INNER JOIN
produtos p ON pe.idproduto = p.idproduto)
WHERE (e.fim >= NOW) AND (e.inicio <= NOW)
This result was expected, however I would like the names of the products that are present in the event to be in the same column, that is, I would like that instead of 4 results, each with a product, I would like 1 result with the 4 products in this way:
Name: x-All, X-All², Calabrian Portion, Fried Portion.
Does anyone have any hint of what must be done to achieve this result?
Use the GROUP_CONCAT aggregation function together with the GROUP BY clause.
– anonimo
I used it, it stayed like this:
SELECT e.titulo, e.descricao, e.obs, e.cupom, e.inicio, e.fim, GROUP_CONCAT(p.nome) AS teste
FROM ((eventos e INNER JOIN
 ProdutosEventos pe ON e.idevento = pe.idevento) INNER JOIN
 produtos p ON pe.idproduto = p.idproduto)
WHERE (e.fim >= NOW) AND (e.inicio <= NOW)
GROUP BY e.idevento
But it returns an error: https://i.stack.Imgur.com/jkMpJ.png Know what would be?– Leandro Ribeiro
What is the comic ? Mysql ?
– Motta
Access, I am developing in VB.NET
– Leandro Ribeiro
If you are using Access why did you tag Mysql? To my knowledge Microsoft Access does not have a similar aggregation function as Mysql GROUP_CONCAT.
– anonimo
You don’t know if you have any way to concatenate in Access?
– Leandro Ribeiro
https://stackoverflow.com/questions/2852892/is-there-a-group-concat-function-in-ms-access?rq=1 solving in the application , Acess is very limited.
– Motta