以为通过命令直接删除就可以了,总是报错:
delete from test
where name in(select name from test as t having count(name)>1)
发现在这只能建立临时表格,方法1设计可行:
1. 首先先创建一个临时表,然后将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 临时表
2.方法2直接使用语句:
delete from test
where name in(select t.name from (select name from test) as t having count(t.name)>1)
and name not in(select min(id) from(select id,name from test group by name)as tt having count(tt.name)>1)
发现总是删错数据,还未得到验证这种查询是否可行