ID | title | category |
---|---|---|
1 | test | a |
1 | test | b |
2 | test2 | c |
2 | test2 | d |
3 | test3 | e |
3 | test3 | f |
I have a table like above in mysql.
I want to group the "category" with the same ID as below.
ID | title | category |
---|---|---|
1 | test | a,b |
2 | test2 | c,d |
3 | test3 | e,f |
I want to achieve this with mysql.
In that case, what kind of sql statement should be executed?
2
Answers
You can also only repeat distinct values as such
You can do it as follows :
You can also use
SEPARATOR
andORDER BY
inside theGROUP_CONCAT
function :