Search code examples
mysqlsqlconcatenationgroup-concat

How can I convert multiple column into one column with comma separated value in MySql


I have a MySql table with 15 Column and I want to get all the value of last 12 column into one column with comma separated.

My table name is like MyTable-

User Name     User ID     JAN   FEB   MAR   APR ...
User 01       001         10     30    40    50 ....
User 02       002          44     54   33    90 ..

I want the result like -

User Name     User ID     Values
User 01       001         '10','30','40','50'
User 02       002         '44','54','33','90'

How can i do that into MySql Query.

Thanks for advice.


Solution

  • use concat

    select username,userid,concat(jan,',',feb,',',mar,',',apr) from table