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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -