sql刪除重複資料

2021-09-05 19:44:54 字數 420 閱讀 3475

sql刪除重複資料

如果該錶需要刪除重複的記錄(重覆記錄保留1條),可以按以下方法刪除

select distinct * into #tmp from tablename

drop table tablename

select * into tablename from #tmp

drop table #tmp

另一種方法是乙個字段重複,id不重複

delete 表 where id not in(

select max(id) as id from 表 group by rows) --- 刪除重複行

select * from 表 where id in(

select max(id) as id from 表 group by rows) --重複行只查詢一條

sql刪除重複資料

1 建立表 create table dbo test id numeric 18,0 identity 1,1 not null primary key,name varchar 200 collate chinese prc ci as null remark varchar 1024 coll...

SQL刪除重複資料

這個應用場景也不多說了 with c as select orderid,row number over partition by orderid order by select null as nfrom sales.myorders delete from c where n 1 利用row n...

sql 刪除重複資料語句

現在有表資料如下圖1 需要刪除表中除id外重複的資料,實現如下圖所示效果圖2 篩選根據name,value分組後id最大的非重複資料 select max id from deleterepeat group by name value 下面是實現效果圖2 的語句 delete from delet...