思路:
先查找重复数据
这里定义id相同即为重复
select info from table_name group by id having count(*)>1
只保留一条,可选择id最大/最小的
select max(id) as store_id from table_name group by id having count(*)>1
上述查出的数据重新命名
(select max(id) as store_id from table_name group by id having count(*)>1) as store_table
这里考虑使用not in 删除不需要存储的数据,则需要对上述语句进行修改,保留只有一条的数据
(select max(id) as store_id from table_name) as store_table
使用not in 选出重复的数据
select info from table_name where table_name.id not in
(select store_table.store_id from
(select max(id) as store_id from table_name) as store_table)
删除此数据
delete from table_name where table_name.id not in
(select store_table.store_id from
(select max(id) as store_id from table_name) as store_table)