您当前的位置: 首页 >  sql

培根芝士

暂无认证

  • 3浏览

    0关注

    446博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

SQL语句查询和删除重复记录

培根芝士 发布时间:2020-12-28 11:36:28 ,浏览量:3

根据单个字段(title)查找表中多余的重复记录

select * from article
where title in (select title from article group by title having count(title) > 1)

根据多个字段查找表中多余的重复记录

select * from article a
where (a.title,a.categoryid) in (select title,categoryid from article group by title, categoryid having count(*) > 1)

 根据单个字段(title)查找并删除表中多余的重复记录,只留有rowid最小的记录

delete from article 
where title in (select title from article group by title having count(title) > 1)
and rowid not in (select min(rowid) from article group by title having count(title)>1)

根据多个字段查找并删除表中多余的重复记录,只留有rowid最小的记录

delete from article a
where (a.title,a.categoryid) in (select title, categoryid from article group by title, categoryid having count(*) > 1)
and rowid not in (select min(rowid) from article group by title, categoryid having count(*)>1)

 

关注
打赏
1660824269
查看更多评论
立即登录/注册

微信扫码登录

0.1607s