MySql 刪除重復(fù)數(shù)據(jù)
tags:mysql 重復(fù)數(shù)據(jù)
假設(shè):表:goods 重復(fù)字段:name
清除表中的重復(fù)數(shù)據(jù)艘款,分步來處理梨熙。
方法一
1、建立一個新表欠啤,將不重復(fù)的數(shù)據(jù)插入新表
create table goods1 as (select * from goods group by name having count(*)=1);
2荚藻、將重復(fù)的數(shù)據(jù)插入新表(僅插入一條)
insert into goods1 (select * from goods group by name having count(*)>1);
3、清空原表(goods表)數(shù)據(jù)
truncate table goods;
4洁段、向goods表中插入數(shù)據(jù)
insert into goods select * from goods1;
方法二
1应狱、2步不變
3、刪除goods表
drop table goods;
4祠丝、將goods1表重命名為goods
rename table goods1 to goods ;