MySql中删除重复记录
时间:2007-05-24 来源:vincentn
表结构:
create table tab_name
(
id tinyint,
name varchar(10),
age tinyint,
phone varchar(15));
原始内容: select * from tab_name;
id name age phone
1 zhangsan 10 12345678910
2 lisi 28 98765432110
3 wangwu 33 45678912312
4 zhaoliu 45 78945612354
2 lisi 28 98765432110
3 wangwu 33 45678912312
删除重复后检索: select * from tab_name group by id,name,age,phone;
id name age phone
1 zhangsan 10 12345678910
2 lisi 28 98765432110
3 wangwu 33 45678912312
4 zhaoliu 45 78945612354
创建另一张表保存删除重复后内容: create table temp select * from tab_name group by id,name,age,phone;
删除原表内容: delete from tab_name;
导入正确记录: insert into tab_name select * from temp;
如只想删除部份记录可带where限定条件: select * from tab_name where id=1 group by id,name,age,phone;
相关阅读 更多 +