第一种方式
delete from tablename where id not in (select max(id) from tablename group by col1,col2,...);第二种方式
select distinct * into temp from tablename; --去除重复行创建新表delete from tablename;//清空原表
insert into tablename select * from temp//从新表插入原表
评价:这种操作牵连大量的数据移动,不适合大容量数据操作.
第三种方式
添加一个自增列例如:在一个外部表中导入数据,由于某些原因第一次只导入了一部分,但很难判断具体位置,这样只有在下一次全部导入,这样也就产生好多重复的字段,怎样删除重复字段
alter table tablename add column_b int identity(1,1);
delete from tablename where column_b not in(select max(column_b) from tablename group by column1,column2,...);
alter table tablename drop column column_b;