GROUP_CONCAT() 上的 MySQL DISTINCT

2021-11-20 00:00:00 mysql group-concat

我正在执行 SELECT GROUP_CONCAT(categories SEPARATOR ' ') FROM table.以下示例数据:

I am doing SELECT GROUP_CONCAT(categories SEPARATOR ' ') FROM table. Sample data below:

categories
----------
test1 test2 test3
test4
test1 test3
test1 test3

但是,我得到 test1 test2 test3 test4 test1 test3 回来,我想得到 test1 test2 test3 test4 回来.有什么想法吗?

However, I am getting test1 test2 test3 test4 test1 test3 back and I would like to get test1 test2 test3 test4 back. Any ideas?

非常感谢!

推荐答案

GROUP_CONCAT 具有 DISTINCT 属性:

GROUP_CONCAT has DISTINCT attribute:

SELECT GROUP_CONCAT(DISTINCT categories ORDER BY categories ASC SEPARATOR ' ') FROM table

相关文章