Sometime we face the problems for concatenating of group rows column value in a single string.
Scenario is like this :
We have a table data Like
1 2 3 4 5 6 7 | a b c 1 100 name1 1 200 name2 2 150 name1 3 120 name1 3 130 name2 3 100 name3 |
now we want result like this :
1 2 3 | 1 300 name1,name2 2 150 name1 3 350 name1,name2,name3 |
How we can achieve concatenating of group by rows value.
GROUP_CONCAT() is a function by which we can concate group rows values.
Syntax
1 | GROUP_CONCAT(expr) |
For getting above result, we have to write query as follows
1 | select a,sum(b),group_concat(c) from table group by a |
Please see here for More details