Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql removes duplicate data

Shulou Source: shulou.com Published: 2022-06-01 06:08:11 10月26日 Update

mysql deduplicates data in two ways:

A field to uniquely identify a record, you can use the following SQL to delete:

delete glt_entity_tmp from glt_entity_tmp,(select idd from glt_entity_tmp group by nam having count(*) > 1 ) as t2

where glt_entity_tmp.idd=t2.idd

Note: idd in the data is inconsistent, and other field information is consistent. If there are more than 2 duplicate records in a nam, multiple executions are required.

Two, with two or more fields to uniquely determine a record, you can use the following SQL to delete, but note that each record must have a third field to uniquely determine this record (use max to delete)

delete gbi_pd_theme_new_tmp from gbi_pd_theme_new_tmp,(select new_code,the_code,max(the_new_code) as the_new_code from gbi_pd_theme_new_tmp group by new_code,the_code having count(*) > 1) as t2

where gbi_pd_theme_new_tmp.new_code=t2.new_code and gbi_pd_theme_new_tmp.the_code=t2.the_code and gbi_pd_theme_new_tmp.the_new_code=t2.the_new_code

Note: If there are more than 2 duplicate records, perform multiple times

Because each record in this example has a unique field, the_new_code, max can be used to remove duplicates

Tags: Fields data consistency for three examples information situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information Docker Redmi MariaDB