DELETE FROM saler_login WHERE username IN( SELECT t.username FROM (SELECT id,username FROM saler_login GROUP BY username HAVING COUNT(1)>1 ) t ) AND id NOT IN (SELECT dt.minid FROM (SELECT MIN(id) AS minid FROM saler_login GROUP BY username HAVING COUNT(1)>1 ) dt );