This question already has answers here:
MySQL DISTINCT on a GROUP_CONCAT()
                                
                                    (6个答案)
                                
                        
                                2年前关闭。
            
                    
我想使用singme SQL查询从表返回唯一的action_id(逗号分隔值)中的数据

例如表:tbl_action

action_id
----------
101
102
103
104
102
105

Output that I want is: 101,102,103,104,105

最佳答案

您可以将Group_concat()函数与Distinct一起使用:

SELECT GROUP_CONCAT(DISTINCT action_id) FROM tbl_action;


如果希望action_id值在逗号分隔的字符串中按升序排列,则可以执行以下操作:

SELECT GROUP_CONCAT(DISTINCT action_id ORDER BY action_id)
FROM tbl_action;

关于mysql - 多行至一个唯一的逗号分隔值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53043791/

10-13 02:04