2

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
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
Crackeraki
  • 263
  • 2
  • 4
  • 9

1 Answers1

6

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;
newfurniturey
  • 37,556
  • 9
  • 94
  • 102