举个例子:
这要删除 id 重复的行,只保留最小的 sql 语句就是:
delete from table_name t1 where rowid not in(
select min(rowid) from table_name t2
where t2.id is not null
having count(id) >1 group by t2.id
)
或者是这样子:
delete from table_name t1 where rowid >(
select min(t2.rowid) from table_name t2
where t1.id=t2.id
)
二者选一拿去用吧.
大致逻辑就是:
子查询筛选出 最小 ,没有重复的 rowid
跟原表比较,删除重复的