SQL操作應用——刪除重復記錄
刪除重復記錄
1),delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)
2),select distinct * into temp from tablename
delete from tablename
insert into tablename select * from temp
評價: 這種操作牽連大量的數(shù)據的移動,這種做法不適合大容量但數(shù)據操作
3),例如:在一個外部表中導入數(shù)據,由于某些原因第一次只導入了一部分,但很難判斷具體位置,這樣只有在下一次全部導入,這樣也就產生好多重復的字段,怎樣刪除重復字段
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
點擊加載更多評論>>