MySQL DISTINCT在GROUP_CONCAT()上 [英] MySQL DISTINCT on a GROUP_CONCAT()
本文介绍了MySQL DISTINCT在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 has DISTINCT attribute:
SELECT GROUP_CONCAT(DISTINCT categories ORDER BY categories ASC SEPARATOR ' ') FROM table
这篇关于MySQL DISTINCT在GROUP_CONCAT()上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文