sql - MySQL - how to find most commonly occuring "tag" in a list of rows -


some context goal "tag" occurs in set of rows returned table (entities). entity in case group of famous people , roles. not have flexibility chage database schema.

e.g. (quick sql table struct)

entityname (varchar) tag1 (varchar) tag2 (varchar) tag3 (varchar) tag4 (varchar) tag5 (varchar) 

example rows returned:

entityname      tag1            tag2            tag3                tag4            tag5 warren buffett  ceo             investor        philathropist       billionaire  bill gates      billionaire     visionary       ceo                 visionary steve jobs      visionary       ceo              oprah           celebrity       entertainment 

what trying do? tag common among sql rows returned. above example, expecting "ceo" (since appears 3 times 4 record). assuming, sql query returns n rows above, how find occuring list of tags?

please help, im not sure how best approach problem. not have flexibility chage database schema..

you can this: make 5 unions this:

select tag1 tag table  union  select tag2 tag table  union  select tag3 tag table  union  select tag4 tag table  union  select tag5 tag table 

and create view it. then:

select tag, count(tag) myview group tag order count(tag) desc 

the first row common tag hope looking for.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -