Delayer
Delayer

Reputation: 439

Merge multiple rows into one column

I'm trying to merge different old values in one single column. I have this table

id  code    langtype    desc        duration            
232 1104466 1           IT text     10
233 1104466 2           EN text     10
234 1104466 6           other desc  10
235 1104466 1           Other IT text(different row) 10
236 1104466 2           Other EN text(same row of previous) 10

And i would like to obtain a result like this

id  code    desc                                                duration
232 1104466 “IT” = “IT TEXT”, EN=”EN TEXT”, “ES”=”Other desc”   10

It is possibile is mysql?

Thank you

Upvotes: 0

Views: 47

Answers (1)

Rogach
Rogach

Reputation: 27200

Yes, it is possible. Something like this should achieve this effect:

select group_concat(concat(langtype, ' = ', desc))
from table
group by code

Here we first form a value to be extracted from each row (concat(langtype, ' = ', desc)) and then concatenate it for each grouped row (group_concat). You can change delimiters, or add quotes where you need - look at GROUP_CONCAT and CONCAT docs.

Upvotes: 1

Related Questions