There is an enter table with id, uid, date fields.

You need to extract 5 uid , which occur most often, from the most common, and, accordingly, another 4, inferior to the first.

How can this be implemented? I myself cannot reach any ideas.

    2 answers 2

    Will return the 5 most common uid and number of times they met in the count table

      select count(uid) as count, uid from enter group by uid order by count desc limit 5 
    • It seems to me - you need to fix it! Instead of id in select , you need uid . - Majestio
    • @Majestio, thanks. Corrected - Vadim Prokopchuk

    Like this (tried for for MySQL):

     SELECT u.uid, COUNT(u.uid) FROM enter AS u GROUP BY u.uid ORDER BY COUNT(u.uid) DESC LIMIT 5