I have a similar question to How to use GROUP BY to concatenate strings in MySQL? , however for this example for mytable
table
id string aggr
1 A NULL
1 B NULL
2 F NULL
The difference is I need to update the table to get this results:
id string aggr
1 A A|B|
1 B A|B|
5 C C|E|C|
5 E C|E|C|
5 C C|E|C|
2 F F|
As result the same id
we have the same newcolumn
values.
It is absolutely fine to add a delimiter |
at the very end of the string. That way I can even faster count how many "items" are in the newcolumn
without adding +1
because of the absense at the very end (just in between). Also I won't care about validation (if I have a pipe right before) when appending another part or two into aggr
column.
Thank you.