Delete duplicated records from a table without pk or id or unique columns in mysql

前端 未结 4 1536
北荒
北荒 2021-01-20 22:30

I need to delete all the duplicated records from one of my tables the problem is that there isn\'t any id or unique or key column so I can\'t make something like this:

4条回答
  •  醉梦人生
    2021-01-20 22:54

    its pretty simple just make a temporary table and drop the other table then recreate it

    CREATE TEMPORARY TABLE IF NOT EXISTS no_dupes AS 
    (SELECT * FROM test GROUP BY phone, address, name, cellphone);
    
    TRUNCATE table test;
    INSERT INTO test (phone, address, name, cellphone) 
    SELECT phone, address, name, cell FROM no_dupes;
    

    WORKING DEMO

提交回复
热议问题