The minimum id for Mysql to delete duplicate data and the minimum id for mysql to retain

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.