开发者

MySQL - Select concatenate 2 values with 1 id

开发者 https://www.devze.com 2023-02-13 10:12 出处:网络
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:

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

精彩评论

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

关注公众号