SQL操作應(yīng)用——刪除重復(fù)記錄
刪除重復(fù)記錄
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ù)據(jù)的移動,這種做法不適合大容量但數(shù)據(jù)操作
3),例如:在一個外部表中導(dǎo)入數(shù)據(jù),由于某些原因第一次只導(dǎo)入了一部分,但很難判斷具體位置,這樣只有在下一次全部導(dǎo)入,這樣也就產(chǎn)生好多重復(fù)的字段,怎樣刪除重復(fù)字段
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
點擊加載更多評論>>