当前位置:网站首页>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)
边栏推荐
- vulnhub-XXE ctf security question
- C#中对委托的理解和使用
- oracle行转列、列转行总结
- TypeError The view function did not return a valid response. The function either returned None 的解决
- jsonpath
- Go简单实现协程池
- 学生管理系统
- Misc of CTF-image steganography
- Solution to TypeError The view function did not return a valid response. The function either returned None
- Flink CDC 实现Postgres到MySQL流式加工传输案例
猜你喜欢

sqli-labs less3/4 Targeting Notes

Nacos配置中心用法详细介绍

uni-app installs components using npm commands

DVWA installation tutorial (understand what you don't understand · in detail)

通信中间件 Fast DDS 基础概念简述与通信示例

Flink CDC 实现Postgres到MySQL流式加工传输案例

sqli-labs shooting range SQL injection learning Less-1
Misc of CTF-image steganography

C#预定义数据类型简介

【数仓】数据仓库高频面试题题英文版(1)
随机推荐
C#下大批量一键空投实现
C#中使用OleDb操作access数据库
C# WPF中监听窗口大小变化事件
C#预定义数据类型简介
学生管理系统
【SQL】SQL 高频面试题英语版(1)
【面经】米哈游数据开发面经
C# WPF下限制TextBox只输入数字、小数点、删除等键
CTF之misc-日志分析
The number of warehouse 】 data quality
CTF之misc-图片隐写
Online sql editing query tool sql-editor
CTF之misc-其他类型隐写
【数仓】数据仓库高频面试题题英文版(1)
史上超强最常用SQL语句大全
[HCTF 2018]admin
MySQL storage engine
CTF之misc-音视频隐写
uni-app使用npm命令安装组件
[Mini Program Project Development--Jingdong Mall] Classification Navigation Area of uni-app