主頁(yè) > 知識(shí)庫(kù) > 分享SQL Server刪除重復(fù)行的6個(gè)方法

分享SQL Server刪除重復(fù)行的6個(gè)方法

熱門(mén)標(biāo)簽:服務(wù)外包 網(wǎng)站排名優(yōu)化 鐵路電話(huà)系統(tǒng) 百度競(jìng)價(jià)排名 Linux服務(wù)器 呼叫中心市場(chǎng)需求 地方門(mén)戶(hù)網(wǎng)站 AI電銷(xiāo)
1.如果有ID字段,就是具有唯一性的字段
復(fù)制代碼 代碼如下:

delect table where id not in (
select max(id) from table group by col1,col2,col3...
)

group by 子句后跟的字段就是你用來(lái)判斷重復(fù)的條件,如只有col1,那么只要col1字段內(nèi)容相同即表示記錄相同。

2. 如果是判斷所有字段也可以這樣
復(fù)制代碼 代碼如下:

select * into #aa from table group by id1,id2,....
delete table
insert into table
select * from #aa

3. 沒(méi)有ID的情況
復(fù)制代碼 代碼如下:

select identity(int,1,1) as id,* into #temp from tabel
delect # where id not in (
select max(id) from # group by col1,col2,col3...)
delect table
inset into table(...)
select ..... from #temp

4. col1+','+col2+','...col5 聯(lián)合主鍵
復(fù)制代碼 代碼如下:

select * from table where col1+','+col2+','...col5 in (
select max(col1+','+col2+','...col5) from table
where having count(*)>1
group by col1,col2,col3,col4
)

group by 子句后跟的字段就是你用來(lái)判斷重復(fù)的條件,如只有col1,那么只要col1字段內(nèi)容相同即表示記錄相同。

5.
復(fù)制代碼 代碼如下:

select identity(int,1,1) as id,* into #temp from tabel
select * from #temp where id in (
select max(id) from #emp where having count(*)>1 group by col1,col2,col3...)

6.
復(fù)制代碼 代碼如下:

select distinct * into #temp from tablename
delete tablename
go
insert tablename select * from #temp Sqlclub
go
drop table #temp

以上就是SQL Server刪除重復(fù)行的方法介紹。
您可能感興趣的文章:
  • 刪除DataTable重復(fù)列,只刪除其中的一列重復(fù)行的解決方法
  • sqlserver利用存儲(chǔ)過(guò)程去除重復(fù)行的sql語(yǔ)句
  • 刪除Table表中的重復(fù)行的方法
  • SQLServe 重復(fù)行刪除方法
  • 批處理 刪除重復(fù)行的代碼
  • 用vbscript實(shí)現(xiàn)從文本文件中刪除所有重復(fù)行的代碼
  • sql里將重復(fù)行數(shù)據(jù)合并為一行數(shù)據(jù)使用逗號(hào)進(jìn)行分隔

標(biāo)簽:衡水 仙桃 湖南 蘭州 銅川 湘潭 黃山 崇左

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《分享SQL Server刪除重復(fù)行的6個(gè)方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話(huà)咨詢(xún)

    • 400-1100-266