当前位置:网站首页>mysql delete duplicate data in the table, (retain only one row)
mysql delete duplicate data in the table, (retain only one row)
2022-07-30 06:47:00 【that's the name】
The data in the example table is as follows:
According to uniqle_idThis column is used to determine whether the data is repeated
1. Check the repeated data
select uniqle_id,name from person group by uniqle_id having count(span>uniqle_id) > 1The result is as follows:
2. Remove duplicatesColumn, only keep the row with the smallest id
delete from person where uniqle_id in (select * from(select min(uniqle_id) from person group by uniqle_idhaving count(uniqle_id) > 1) temp)and id not in(select * from(select min(id) from person group by uniqle_idhaving count(uniqle_id)> 1 )temp2)3. Delete all duplicate lines
delete from person where uniqle_id in (select * from(select min(uniqle_id)as uniqle_id from person groupby uniqle_id having count(uniqle_id) > 1) temp)(The purpose of temp in sql is to give the result of the sub-query an alias. If this alias is not available, an error will be reported: SQL error [1248] [42000]: Every derived table must have its own alias)
边栏推荐
猜你喜欢

Thread state of five

uni-app: about custom components, easycom specs, uni_modules, etc.

国内数字藏品交易平台开发市场会开放二级市场吗

FastAPI 快速入门

Using PyQt5 to add an interface to YoloV5 (1)

oracle row to column, column to row summary
![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
Volatility memory forensics - command shows
![[Mini Program Project Development--Jingdong Mall] Classification Navigation Area of uni-app](/img/cb/b0b79444dc90980cd2220ff9e68549.png)
[Mini Program Project Development--Jingdong Mall] Classification Navigation Area of uni-app
![[PASECA2019]honey_shop](/img/8f/7161a63dab10dc02fef1fea075401a.png)
[PASECA2019]honey_shop
随机推荐
【数仓】数据仓库高频面试题题英文版(1)
CTF之misc-图片隐写
Obtain geographic location and coordinates according to ip address (offline method)
[PASECA2019]honey_shop
【SQL】first_value 应用场景 - 首单 or 复购
C#下利用开源NPlot绘制股票十字交叉线
C#利用开源NPlot实现K线图(蜡烛图)
【十年网络安全工程师整理】—100渗透测试工具使用方法介绍
ClickHouse查询语句详解
Bypassing the file upload vulnerability
C#下大批量一键空投实现
Misc of CTF - other types of steganography
CTF之misc-内存分析(Volatility)
Online sql editing query tool sql-editor
MySQL - 函数及约束命令
Mycat2.0搭建教程
kali is an essential artifact for information security
[Mozhe Academy] Identity Authentication Failure Vulnerability Actual Combat
C#中对委托的理解和使用
MySQL 索引优化及失效场景