Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql group by comma separated values

Tags:

select

mysql

tags

I have a mysql table comments in that table a field is tags and all tags are comma separated like

Comments Table

Name   Reply   Tags
a      b       new,old,facebook,fb
b      d       water,faebook,wall
b      r       wall,php,fb
c      q       name,facebook,email
a      y       weather,cold,old
a      w       twitter,next,pet,fb

I need to get most used tag in this table with mysql query..

like image 479
Huzoor Bux Avatar asked Mar 19 '12 11:03

Huzoor Bux


1 Answers

I think that the best approach is to use a separate table for Tags and for the relation between Tags and your table (i.e.: CommentTags), it'll allow you to quickly find those comments that use any speciffic tag, do statistics, etc. With your current approach, you end up using a string splitting for each row, each time.

Now, if you are stuck with your current approach, here is a question about string splitting that you may find useful. But I foresee a great deal of performance complains by users...

like image 179
Alejandro B. Avatar answered Nov 01 '22 17:11

Alejandro B.