当前位置:网站首页>mysql删除表中重复数据,(只保留一行)
mysql删除表中重复数据,(只保留一行)
2022-07-30 05:42:00 【就是叫这个名字】
示例表中数据如下:
根据uniqle_id这一列来判断数据是否重复
1.查看重复的数据有哪些
select uniqle_id,name from person group by uniqle_id having count(uniqle_id) > 1
结果如下:
2.删除重复的列,只保留id最小的一行
delete from person where uniqle_id in (
select * from
(select min(uniqle_id) from person group by uniqle_id having count(uniqle_id) > 1) temp
)
and id not in
(select * from
(select min(id) from person group by uniqle_id having count(uniqle_id)> 1 )temp2
)
3.删除所有重复的行
delete from person where uniqle_id in (
select * from
(select min(uniqle_id)as uniqle_id from person group by uniqle_id having count(uniqle_id) > 1) temp
)
(sql中的temp存在的作用是给子查询的结果起一个别称,如果不起这个别称的话,会报错:SQL 错误 [1248] [42000]: Every derived table must have its own alias)
边栏推荐
- Solution to TypeError The view function did not return a valid response. The function either returned None
- Bypassing the file upload vulnerability
- vulnhub-XXE ctf安全真题
- Operators and Interaction Basics
- 【文献阅读】Age Progress/Regression by Conditional Adversarial Autoencoder 基于条件对抗自编码器(CAAE)的老化/去龄化方案
- volatility内存取证----命令演示
- 搞懂redux一篇就够了
- Monstache执行monstache -f config.toml出错No processor type exists with name [attachment] [type=parse_exc
- TDengineGUI无法连接TDengine
- 【墨者学院】身份认证失效漏洞实战
猜你喜欢
随机推荐
node包的导入与导出
[Mini Program Project Development--Jingdong Mall] Classification Navigation Area of uni-app
Student management system
史上超强最常用SQL语句大全
MongoDB快速入门与基本使用
Bypassing the file upload vulnerability
npm run serve starts error npm ERR Missing script "serve"
Understand JDBC in one article
Solution to TypeError The view function did not return a valid response. The function either returned None
使用Context API维护全局状态
Remember a traffic analysis practice - Anheng Technology (August ctf)
Jackson serialization failure problem - oracle data return type can't find the corresponding Serializer
【调优】一个 Spark 任务某天突然变慢怎么解决
Misc of CTF-Memory Analysis (Volatility)
uncategorized SQLException; SQL state [null]; error code [0]; sql injection violation, syntax error
【文献阅读】Age Progress/Regression by Conditional Adversarial Autoencoder 基于条件对抗自编码器(CAAE)的老化/去龄化方案
Blind injection, error injection, wide byte injection, stack injection study notes
uni-app:关于自定义组件、easycom规范、uni_modules等问题
文件上传漏洞的绕过
torch distributed training






