当前位置:网站首页>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)
边栏推荐
猜你喜欢
Remember a traffic analysis practice - Anheng Technology (August ctf)

一类SMS漏洞的防御思路

C#下利用开源NPlot绘制股票十字交叉线
misc-file steganography of CTF
![Monstache执行monstache -f config.toml出错No processor type exists with name [attachment] [type=parse_exc](/img/2d/50c9001125cd613087044d2b6c78b1.png)
Monstache执行monstache -f config.toml出错No processor type exists with name [attachment] [type=parse_exc

FastAPI 快速入门

3 minutes to tell you how to become a hacker | Zero foundation to hacker introductory guide, you only need to master these five skills
CTF之misc-内存分析(Volatility)

使用Nodejs搭建Web Server(入门教程)
![[MATLAB]图像处理——交通标志的识别](/img/45/1a5797a17ebf6db965a64c85e0f037.png)
[MATLAB]图像处理——交通标志的识别
随机推荐
jsx的实现
uncategorized SQLException; SQL state [null]; error code [0]; sql injection violation, syntax error
简述SSRF
Misc of CTF-image steganography
C# WPF中监听窗口大小变化事件
关于浅拷贝和深拷贝,草稿闲了写
Deserialization character escape
【SQL】SQL 高频面试题英语版(1)
CTF之misc-文件隐写
npm run serve启动报错npm ERR Missing script “serve“
C#中default关键字用法简介
sqli-labs less3/4 Targeting Notes
promise的基本概念
Dcat Admin 安装
Blind injection, error injection, wide byte injection, stack injection study notes
在不同的服务器上基于docker部署redis主从同步
php vulnerability full solution
反序列化字符逃逸
async/await用法详解
The Request request body is repackaged to solve the problem that the request body can only be obtained once