views:

34

answers:

2

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

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

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

Many thanks!

+3  A: 

GROUP_CONCAT has DISTINCT attribute:

SELECT GROUP_CONCAT(DISTINCT categories ORDER BY categories ASC SEPARATOR ' ') FROM table
Naktibalda
+1  A: 

Using DISTINCT will work

SELECT GROUP_CONCAT(DISTINCT(categories) SEPARATOR ' ') FROM table

REf:- this

Salil
+1 for link....
Aditya