当前位置:网站首页>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)
边栏推荐
- torch distributed training
- 2022CISCNmisc
- kali is an essential artifact for information security
- uni-app: about custom components, easycom specs, uni_modules, etc.
- async/await用法详解
- 记一次流量分析实战——安恒科技(八月ctf)
- CTF之misc-内存分析(Volatility)
- Flink PostgreSQL CDC配置和常见问题
- 互联网商城盲盒app为何如此火爆
- TypeError The view function did not return a valid response. The function either returned None 的解决
猜你喜欢
Awd summary
【墨者学院】身份认证失效漏洞实战
misc-file steganography of CTF
awd——waf部署
[Mini Program Project Development--Jingdong Mall] Classification Navigation Area of uni-app
Jackson serialization failure problem - oracle data return type can't find the corresponding Serializer
【数仓】数据仓库高频面试题题英文版(1)
强国杯初赛WP
【面经】米哈游数据开发面经
PHP-fpm
随机推荐
SSTI靶场
【文献阅读】Age Progress/Regression by Conditional Adversarial Autoencoder 基于条件对抗自编码器(CAAE)的老化/去龄化方案
Arrays工具类的使用
uncategorized SQLException; SQL state [null]; error code [0]; sql injection violation, syntax error
setAttribute()方法
简述SSRF
网上说的挖矿究竟是什么? 挖矿系统开发详解介绍
CTFSHOW命令执行【web29-web124】未完待续
php vulnerability full solution
CTF之misc-文件隐写
利用自定义注解,统计方法执行时间
3分钟告诉你如何成为一名黑客|零基础到黑客入门指南,你只需要掌握这五点能力
Remember a traffic analysis practice - Anheng Technology (August ctf)
npm run serve启动报错npm ERR Missing script “serve“
DVWA安装教程(懂你的不懂·详细)
Misc of CTF-image steganography
【数仓】数据仓库高频面试题题英文版(1)
C#预定义数据类型简介
攻防世界easy_web
运算符和交互基础