php - how to get rows that repeated X times or more? -


i have table contains data. have 'username' field in table stores users username.

in table there possible user have many records.

now, how can users username repeated more x times? (50 time or more example?) , after want delete rows each user in previous step need keep first x rows , need delete rows after row x each user.

how can mysql , php?


update: solve problem this:

select username, count(*) numrecords table group username 

this take number of steps achive..

start building query count number of records each user

select username, count(*) numrecords table group username 

then add:

having numrecords > 5 

to narrow down usernames more 5 records..

loop through records query above..

foreach($results $result){      // query db using `username` 'record keep'     "select * table       username = $result['username']      order someuniqueid      limit 1"      __execute query__      __store record id keep__     // delete records (except 1 keep)    "delete table     username = $result['username']     , someuniqueid != $someuniqueid"      __execute query__  } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -