开发者

MySQL - Select concatenate 2 values with 1 id

For example, I have a table 'Map':

Map:

id | place
__________
1  | a
1  | b
2  | a
2  | b
2  | c

What MySQL query can I use for me to have the following results:

id | place
__开发者_C百科________
1  | a,b
2  | a,b,c


You should use the group_concat() function for this. You can use it as follows.

SELECT id,group_concat(DISTINCT place ORDER BY place ASC SEPARATOR ',') 
FROM Map
GROUP BY ID
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜