删除重复数据

159 阅读1分钟
数据库删除重复数据的方式有很多种,单纯记录自己常用的,后续会继续更新
  • Oracle
--仅保留最小rowid数据
delete from tablename t1 where t1.rowid > (select min(rowid) from tablename t2 where t1.clomun =t2.column);
--这个与上面的没什么区别
delete from tablename t1 where t1.rowid > (select min(rowid) from tablename t2 where t1.clomun =t2.column group by column);
--这种group by ...having需要具体问题具体分析,记得带上指定条件
delete from tablename where sex = '男' and id not in (select max(id) from tablename group by column having count(cloumn) > 1);
--原理是根据需求分组查询出重复数据,再做处理,至于distinct也是一样的
select column from X_1670557535019 group by column having count(column) > 1