当前位置:网站首页>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)
边栏推荐
猜你喜欢
![[Mozhe Academy] Identity Authentication Failure Vulnerability Actual Combat](/img/c3/4a4e23a97e4650a17ff5cfc5233043.png)
[Mozhe Academy] Identity Authentication Failure Vulnerability Actual Combat
文件上传漏洞的绕过

3 minutes to tell you how to become a hacker | Zero foundation to hacker introductory guide, you only need to master these five skills

mysql不是内部或外部命令,也不是可运行的程序或批处理文件解决

C#下大批量一键空投实现

Connect to Mysql in the cloud server Docker detailed graphic and text operations (full)

uni-app:关于自定义组件、easycom规范、uni_modules等问题
phpok网站漏洞利用分析
Misc-traffic analysis of CTF

uni-app: The use of uni-icons and how to customize icons
随机推荐
【无标题】ES5新特性
c#下Web3合约空投、转账调用代码
MySQL storage engine
文件上传漏洞的绕过
Dcat Admin installation
uni-app installs components using npm commands
使用Nodejs搭建Web Server(入门教程)
POI工具类
Arrays工具类的使用
TypeError The view function did not return a valid response. The function either returned None 的解决
phpok网站漏洞利用分析
连接云服务器Docker中的Mysql 详细图文操作(全)
Volatility memory forensics - command shows
浏览器缓存
互联网商城盲盒app为何如此火爆
3分钟告诉你如何成为一名黑客|零基础到黑客入门指南,你只需要掌握这五点能力
[Mozhe Academy] Identity Authentication Failure Vulnerability Actual Combat
php漏洞全解
uncategorized SQLException; SQL state [null]; error code [0]; sql injection violation, syntax error
信息安全必备神器之kali