当前位置:网站首页>mysql remove duplicate data
mysql remove duplicate data
2022-07-30 21:36:00 【bhegi_seg】
mysql remove duplicate data
Query duplicate data according to one column (judging duplicate data according to single column)
SELECT * FROM tab_test
WHERE ONE IN (SELECT ONE FROM testdelete GROUP BY ONE HAVING COUNT(ONE) >1)
Delete duplicate records in the table: (delete according to a single column and keep the one with the smallest ID)
DELETE
FROM tab_test
WHERE ONE IN(SELECT
ONE
FROM (SELECT
ONE
FROM tab_test
GROUP BY ONE
HAVING COUNT(ONE) > 1) a)
AND id NOT IN(SELECT
*
FROM (SELECT
MIN(id)
FROM tab_test
GROUP BY ONE
HAVING COUNT(ONE) > 1) b);
Judging repetition according to one,two,three: (Judging repetition according to single and multiple)
SELECT * FROM tab_test a
WHERE (a.one,a.two,a.three) IN
(SELECTONE,two,three FROM tab_test GROUP BY ONE,two,three HAVING COUNT(*) > 1) ;
Delete duplicate data in the table (delete according to multiple columns and keep the one with the smallest ID)
DELETE
FROM tab_test
WHERE (ONE,two,three)IN(SELECT
ONE,
two,
three
FROM (SELECT
ONE,
two,
three
FROM tab_test
GROUP BY ONE,two,three
HAVING COUNT(* ) > 1) a)
AND id NOT IN(SELECT
MIN(id)
FROM (SELECT
MIN(id) AS id
FROM tab_test
GROUP BY ONE,two,three
HAVING COUNT( * ) > 1) b)
Find redundant duplicate records (multiple fields) in the table, excluding the record with the smallest id (check duplicates based on multiple fields but not include the smallest id)
SELECT *
FROM tab_test a
WHERE(a.one,a.two,a.three)IN(SELECT
ONE,
two,
three
FROM tab_test
GROUP BY ONE,two,three
HAVING COUNT( * ) > 1)
AND id NOT IN(SELECT
MIN(id) AS id
FROM tab_test
GROUP BY ONE,two,three
HAVING COUNT( * ) > 1);
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
- [Deep Learning] Target Detection | SSD Principle and Implementation
- JDBC(详解)
- ClickHouse 创建数据库建表视图字典 SQL
- navicat连接MySQL报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password YES)
- 面试难题:分布式 Session 实现难点,这篇就够!
- DistSQL 深度解析:打造动态化的分布式数据库
- MySQL 8.0.29 设置和修改默认密码
- 关于MySQL主从复制的数据同步延迟问题
- Niu Ke Xiaobaiyue Race 53 A-E
- MySql创建数据表
猜你喜欢
【Network Security Column Directory】--Penguin Column Navigation
系统结构考点之CRAY-1向量处理机
面试难题:分布式 Session 实现难点,这篇就够!
外包干了三年,废了...
MySQL60 homework
ClickHouse 创建数据库建表视图字典 SQL
关于MySQL主从复制的数据同步延迟问题
About the data synchronization delay of MySQL master-slave replication
Navicat连接MySQL时弹出:1045:Access denied for user ‘root’@’localhost’
【机器学习】梯度下降背后的数学之美
随机推荐
Day 16 of HCIP
About the data synchronization delay of MySQL master-slave replication
Deep Non-Local Kalman Network for VideoCompression Artifact Reduction
共用体、共用体与结构体的区别、枚举之C语言犄角旮旯的知识
MySQL 游标
【网络安全专栏目录】--企鹅专栏导航
面试难题:分布式 Session 实现难点,这篇就够!
系统结构考点之PM2I单级网络
8 ways to get element attributes in JS
[Deep Learning] Target Detection | SSD Principle and Implementation
Markdown的使用
nVisual网络可视化管理平台功能和价值点
在IDEA中使用JUnit4和JUnitGenerator V2.0自动生成测试模块
系统结构考点之CRAY-1向量处理机
bgp路由过滤
数据指标口径不统一、重复开发?亿信ABI指标管理平台帮你解决
ValueError: Append mode is not supported with xlsxwriter解决方案
外包干了三年,废了...
navicat新建数据库
MySQL user authorization