2
votes

I have something like this:

id  | month | col |  col2
--------------------------
101 |  Jan  |   A  |  B    
102 |  feb  |   C  |  A    
102 |  feb  |   D  |  Q 

And i need something like this:

id  | month |  col  |  col2
----------------------------
101 |  Jan  |  A    |  B    
102 |  feb  |  C,D  |  A,Q
1

1 Answers

6
votes

To get the desired output, you'll want to look into GROUP_CONCAT():

SELECT
    id, month,
    GROUP_CONCAT(col) AS col,
    GROUP_CONCAT(col2) AS col2
FROM
    your_table
GROUP BY
    id, month;