mysql - How can I filter a table with duplicate entries to display the rows that exist the most? -


i hope question makes sense.. have table called genre_tags contains music_id , genre_id column

it can contain duplicate entries

music_id | genre_id 281           3 281           3 281           4 243           7 90            6 90            6 90            10 

what want retrieve duplicate entries based on genre_id

so based on example above left result

music_id | genre_id 281        3 243        7 90         6 

try this,

select  music_id, genre_id    tablename group   music_id, genre_id having  count(*) = (select count(*) total                         tablename b                     a.music_id = b.music_id                     group   music_id, genre_id                     order total desc                     limit 1) 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -