select distinct * into #tmp from tablename go delete from tablename go insert into tablename select * from #tmp go
如果是foxpro,select distinct *into table tablename from source_tablename 若是sql server:select distinct *into tablename from source_tablename
delete from tablename where id in (select max(id) from tablename group by username having count(*)>1)
delete 你的表 where 编号 not in (select min(编号) from 你的表 group by username having sum(1)>1)
如果你的表没有编号:alter table 表 add 编号 int identity(1,1)delete 你的表 where 编号 not in (select min(编号) from 你的表 group by username having sum(1)>1)alter table 表 drop column 编
go
delete from tablename
go
insert into tablename
select * from #tmp
go
from source_tablename
若是sql server:select distinct *into tablename
from source_tablename
(select max(id) from tablename group by username having count(*)>1)