Query mysql to get data from two rows and join in just one

2

Hello, I can not execute a query in mysql. I have a table that has the following fields:

numero | data       | descricao | norma
 001   | 2017-02-28 | Lapis     | NBR
 001   | 2017-02-28 | Lapis     | ISO

As in the example above, there are records that have the same number, date, and description, but the standard is different, so the query returns more than one row as a result.

I've tried using Distinct, group by but it did not work.

How can I mount this query to return me on a single line: the number,  the date, the description that are the same and join in the same line the two standards?

    
asked by anonymous 30.09.2017 / 19:54

1 answer

3

I think what you're looking for is group_concat .

You can make a select of the fields you want to display, with a group_concat in the field you want to join, and grouping by the fields that are the same.

More or less like this:

SELECT 'numero', 'data', 'descricao',  group_concat('norma') as norma
FROM suatabela
GROUP BY 'numero', 'data', 'descricao'
    
01.10.2017 / 01:38