2014年12月03日 星期三

USING 在mysql 删除重复数据只保留一条记录的应用

DELETE FROM tb_users USING tb_users,( SELECT DISTINCT MIN(username) AS username,user_id FROM tb_users GROUP BY username HAVING COUNT(1) > 1 ) AS t2 WHERE tb_users.username = t2.username AND tb_users.user_id <> t2.user_id