How to concatenate results from an SQL

Asked

Viewed 49 times

0

I have two tables: Produtos, Eventos and Productsprovents(coming from the many ratio for many of the tables Products and Events): inserir a descrição da imagem aqui

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)

Upshot:inserir a descrição da imagem aqui

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.

  • 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&#xA;FROM ((eventos e INNER JOIN&#xA; ProdutosEventos pe ON e.idevento = pe.idevento) INNER JOIN&#xA; produtos p ON pe.idproduto = p.idproduto)&#xA;WHERE (e.fim >= NOW) AND (e.inicio <= NOW)&#xA;GROUP BY e.idevento But it returns an error: https://i.stack.Imgur.com/jkMpJ.png Know what would be?

  • What is the comic ? Mysql ?

  • Access, I am developing in VB.NET

  • 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.

  • You don’t know if you have any way to concatenate in Access?

  • https://stackoverflow.com/questions/2852892/is-there-a-group-concat-function-in-ms-access?rq=1 solving in the application , Acess is very limited.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.