The minimum id for Mysql to delete duplicate data and the minimum id for mysql to retain
Search for the data with the smallest id to delete duplicate data on the Internet. The method is as follows:
1 DELETE 2 FROM 3 people 4 WHERE 5 peopleName IN ( 6 SELECT 7 peopleName 8 FROM 9 people10 GROUP BY11 peopleName12 HAVING13 count(peopleName) > 114 )15 AND peopleId NOT IN (16 SELECT17 min(peopleId)18 FROM19 people20 GROUP BY21 peopleName22 HAVING23 count(peopleName) > 124 )
When you use it yourself, an error is displayed:
1 delete from tb where id in (SELECT max(id) from tb GROUP BY user HAVING count(user)>1)
[Err] 1093-You can't specify target table 'xxx' for update in FROM clause
I do not know why.
Then try to perform the distribution 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, the redundant data is deleted one by one based on the obtained max (id ).
1 delete from tb where id=xx
It is a stupid method. Let's solve the problem first.