面试的时候经常会有删除数据库重复记录的sql
// 数据库有主键id,查找col相同的记录
delete from table t where t.id not in (select min(tb.id) from table tb where tb.col=t.col)
// 数据库中没有主键id,查找col 相同的记录
delete from table t where t.rowid not in (select min(tb.rowid) from table tb where tb.col=t.col)
本文提供两种SQL语句用于删除数据库中的重复记录。一种是数据库含有主键id的情况,另一种是没有主键id的情况。通过这些SQL语句可以有效地清理数据表中的冗余数据。
4618

被折叠的 条评论
为什么被折叠?



