Reputation: 745
It's kinda stupid question and I already made it work using php,but I was wondering can I group all the unique elements in a column separated by comma within my query call.
I have a column with comma separated tags
tag1
, tag2
tag2
, tag3
tag3
, tag1
currently I am making my query with GROUP BY ('tag_col')
which returns as it is (like the list up there). In the end I have to output a loop with all the unique tags, which I've done within my php script.
The question had to begin that by using group by it groups as separate rows that contain for example:
tag1
, tag2
and
tag2
, tag1
Ain't there smarter way to list them all as tag1
,tag2
etc. before sorting it with php.
Upvotes: 1
Views: 424
Reputation: 1408
You can use GROUP_CONCAT
for this i guess, it will allow you to concatenate all of them in one row by using GROUP_CONCAT(tag_col)
and removing your group by.
Then with php you can turn it into an array and from there it's easy to remove any duplicates.
Upvotes: 1