Illegal websites should not initiate any form of manual service requests to our staff. It is strictly prohibited to use honmau Media's technical support services and products to engage in any illegal activities. If discovered, no technical support will be provided.×
Current location:home> news > help and support

How to delete duplicate data with the same id

In website operation and maintenance, multiple pieces of data with duplicate IDs sometimes appear in the database. I want to delete duplicate IDs, but I can't find a good solution. This article records and describes based on the actual situation.Please back up the data when operating the database to avoid irreversible operations and causing unexpected losses.

You see multiple deletion methods on the Internet, but the operation will report an error and send it to people who need to solve the problem.

'Mysql如何删除id相同的重复数据'

Solution:

First check whether there are duplicate data in the table

SELECT id,COUNT(*) FROM table name
GROUP BY id

HAVING COUNT(*) > 1;

Check how much duplicate data there is in total and the statement to delete duplicate data:

'Mysql如何删除id相同的重复数据'

Delete From Table Name Where
id IN (
SELECT id FROM (
SELECT id,COUNT(*) FROM table name
GROUP BY id
HAVING COUNT(*) > 1
) AS a

) Limit number;

limit means the number of items you want to delete. Since the execution speed of delete statements is relatively slow, it is recommended to set a number if there is too much data, such as deleting 1000 or 10000 items first. Otherwise, if the data is too large, mysql execution will crash if it is too slow. If it is rushed to close and then execute, the table will be locked. Unable to operate database.

Table interpretation operation:

1. Check the process, mainly to find the ID of the process whose table is locked

SHOW PROCESSLIST;

2. The process ID of the kill lock table

KILL 10866;//The ID of the immediate process after the number

© Website copyright and disclaimer

1.[honmau Media] independently owns the copyright of all materials on relevant pages of this website;

2. No one is allowed to copy it without the express written permission of [honmau Media];

3. The articles that do not indicate "honmau Media" on this website are all from the Internet and are only for everyone to learn and refer;

4. If there is any infringement/violation/irregularity, please contact customer service QQ or email to delete it, please understand;

5.[honmau Media] reserves the right to correct, modify and update this statement at any time.legal notice

Message Board
* Contact customer service for urgent issues
submitted
submission
Working days: 8:30 - 22:00 Online QQ

customer service

Company Introduction
top