0

How can I use the Group_Concat command to update a table?

Basically, I want to turn this:

SET_1 | SET_2
4       12
4       13
5       12
5       13

Into this:

SET_1 | SET_2
4       12, 13
5       12, 13
Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175

1 Answers1

0

Updating your current table might be complicated. It is better to create a new table, select the data using group_concat and insert it to your new table. And make sure the set_2 column is not an integer or else you'll get an error.

INSERT INTO yournewtable(col1, col2) SELECT set_1, GROUP_CONCAT(set_2) FROM currenttable GROUP BY set_1
Kuro Neko
  • 775
  • 10
  • 18