SQL选出相同记录和删除相同记录

来源:互联网 发布:mac os sierra beta2 编辑:程序博客网 时间:2024/06/05 09:32

选出相同记录的SQL语句是:
select * from tableName where id in (
select id from tableName group by id having count(*) > 1)

删除相同记录的SQL语句是:
delete from tableName where id in (
select id from tableName group by id having count(*) > 1)
注意,这样所有相同的记录都删除了,一条也不剩下。

原创粉丝点击