How does mysql delete duplicate records?

Source: Internet
Author: User
How does mysql delete duplicate records? mysql

The table name is tongxunlu. The field is id sXingMing sXingBie dtShengRi.
Because duplicate inserts and several copies of data are inserted, you want to delete duplicate


Reply to discussion (solution)

For example, how to judge duplicate.

Manually delete ..

You can directly determine whether the values of the sXingMing sXingBie dtShengRi fields are the same, and then delete them as needed.

Delete duplicate records

delete from tongxunlu a where  rowid not in(select max(rowid) from tongxunlu where id=a.id and sXingMing=a.sXingMing and  sXingBie=a. sXingBie and dtShengRi=a.dtShengRi); 

delete from tongxunlu  where  id not in(select max(id) from tongxunlu group by id sXingMing sXingBie dtShengRi;


Groups the criteria for determining the repetition.

The number of data records.
If there is not much data, back up the data table and clear the original table. foreach scans the backup data table and inserts non-repeated data into the original table.
In this way, the problem is solved, and there is no need to make it so advanced.

Only a few pieces of data are deleted directly using a third-party tool.

Delete from tb1 where id in (select id, count (id) as tt from tb. where having tt> 1)
The execution must take a certain amount of time. The key is the amount of data.

Delete from tb1 where id in (select id, count (id) as tt from tb. where having tt> 1 group by $ fn)
Drop group

Learned


Technology Life

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.