在Mysql下如何删除重复的数据~

来源:百度知道 编辑:UC知道 时间:2024/07/03 22:55:11
在Mysql下如何删除重复的数据~但得保留一条~
如:表 author 字段(id name password)

首先先创建一个临时表,然后将author表中无重复的数据拎出来,放进临时表中。
create temporary table 表名
select distinct id,name,password
from author

然后将author表中的记录全部删除。
delete from author

最后将临时表中的记录插入author表中
insert into author (id,name,password)
select id,name,password
from 临时表

建个临时表来处理吧
比如select distinct id, name, password into #tmp
delete from author
insert into author(id name password)
select id, name, password from #tmp
这样做之前最好先备份