删除重复记录并使用mysql只保留一条记录?

时间:2018-05-29 02:22:44

标签: mysql

我使用下面的SQL删除重复记录并仅保留min(id)记录

delete from admin_sync_user 
where login_name in
(select login_name from 
(select login_name from admin_sync_user group by login_name having count(login_name) > 1) as a)
and id not in
(select login_name from
(select min(id) from admin_sync_user group by login_name having count(login_name) > 1) as b)

但我的问题是:SQL只执行如下所示,并且不使用第二个条件。我正在使用MYSQL数据库。有谁知道上面的MySQL有什么问题以及如何修改它?

  delete from admin_sync_user 
    where login_name in
    (select login_name from 
    (select login_name from admin_sync_user group by login_name having count(login_name) > 1) as a)

0 个答案:

没有答案