Search online to delete duplicate data and keep the data with the smallest ID. The method is as follows: DELETE FROM people WHERE peopleName IN ( SELECT peopleName FROM people GROUP BY peopleName HAVING count(peopleName) > 1 ) AND peopleId NOT IN ( SELECT min(peopleId) FROM people GROUP BY peopleName HAVING count(peopleName) > 1 ) When I use it myself, an error message is displayed: It is not known what caused it yet. Then find a way to distribute the operation. First, filter out the data with duplicate users, and then use max() to select the larger row: SELECT max(id) from tb GROUP BY user HAVING count(user)>1 Then delete the redundant data one by one according to the obtained max(id) delete from tb where id=xx This is a stupid method, let’s solve the problem temporarily. Summarize The above is the solution for Mysql to delete duplicate data and retain the smallest ID introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time! You may also be interested in:
|
<<: How to get the real path of the current script in Linux
>>: Analysis of CocosCreator's new resource management system
1. Composite primary key The so-called composite ...
This article shares the specific code of the WeCh...
This article shares the specific code of jQuery...
This is to commemorate the 4 pitfalls I stepped o...
External temporary tables A temporary table creat...
docker attach command docker attach [options] 容器w...
Problem: The null type data returned by mybatis d...
1. Go to the official website to download the jdk...
A dynamic clock demo based on Canvas is provided ...
Table of contents Writing Background Project Desc...
If the developer uses Dockerfile to build the ima...
docker-compose-monitor.yml version: '2' n...
There are significant differences between centos7...
When installing Docker on Windows 10, after selec...
Table of contents Overview CommonJS Specification...