How do I delete all the duplicate records in a MySQL table without temp tables

前端 未结 9 1312
北恋
北恋 2020-11-27 03:46

I\'ve seen a number of variations on this but nothing quite matches what I\'m trying to accomplish.

I have a table, TableA, which contain the answers gi

9条回答
  •  自闭症患者
    2020-11-27 04:23

    If you are not using any primary key, then execute following queries at one single stroke. By replacing values:

    # table_name - Your Table Name
    # column_name_of_duplicates - Name of column where duplicate entries are found
    
    create table table_name_temp like table_name;
    insert into table_name_temp select distinct(column_name_of_duplicates),value,type from table_name group by column_name_of_duplicates;
    delete from table_name;
    insert into table_name select * from table_name_temp;
    drop table table_name_temp
    
    1. create temporary table and store distinct(non duplicate) values
    2. make empty original table
    3. insert values to original table from temp table
    4. delete temp table

    It is always advisable to take backup of database before you play with it.

提交回复
热议问题