GROUP_CONCAT() 上的 MySQL DISTINCT [英] MySQL DISTINCT on a GROUP_CONCAT()

查看:51
本文介绍了GROUP_CONCAT() 上的 MySQL DISTINCT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行 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

这篇关于GROUP_CONCAT() 上的 MySQL DISTINCT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆