自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

SQL刪除重復(fù)記錄的四種方式

數(shù)據(jù)庫 SQL Server
SQL數(shù)據(jù)庫中有重復(fù)的記錄?不要著急,使用下面幾種方法,您可以輕松查找到表中多余的重復(fù)記錄,并刪除掉。

在SQL數(shù)據(jù)庫中,經(jīng)常會遇到重復(fù)記錄的情況,那么就需要SQL刪除重復(fù)記錄,下面為您列舉了四種SQL刪除重復(fù)記錄的方式,用于不同的情況,希望對您有所啟迪。

1、查找表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個字段(peopleId)來判斷

  1. select * from people  
  2. where peopleId in (select   peopleId from   people group by   peopleId having count(peopleId) > 1)  

2、SQL刪除重復(fù)記錄,重復(fù)記錄是根據(jù)單個字段(peopleId)來判斷,只留有rowid最小的記錄

  1. delete from people  
  2. where peopleId in (select   peopleId from people group by   peopleId   having count(peopleId) > 1)  
  3. and rowid not in (select min(rowid) from   people group by peopleId having count(peopleId )>1)  

3、查找表中多余的重復(fù)記錄(多個字段)

  1. select * from vitae a  
  2. where (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1) 

4、刪除表中多余的重復(fù)記錄(多個字段),只留有rowid最小的記錄

  1. delete from vitae a  
  2. where (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)  
  3. and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)  

 

 

 

【編輯推薦】

對SQL表結(jié)構(gòu)的查詢

表添加字段的SQL語句寫法

sql查詢中time字段的使用

SQL Xml字段的修改方法

SQL定義Xml字段

責(zé)任編輯:段燃 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-09-03 09:49:39

SQL刪除

2010-09-28 15:46:22

SQL刪除重復(fù)記錄

2010-09-25 16:17:25

SQL語句

2010-10-13 17:07:46

MySQL刪除重復(fù)記錄

2010-09-30 10:29:56

DB2刪除重復(fù)記錄

2010-07-26 17:00:11

SQL Server查

2010-11-23 14:26:02

MySQL刪除重復(fù)記錄

2010-10-27 16:49:23

Oracle刪除重復(fù)記

2010-09-03 11:42:04

SQL刪除

2011-03-21 17:25:08

SQL Server數(shù)重復(fù)記錄

2010-10-27 16:56:05

Oracle重復(fù)記錄

2011-05-24 10:04:39

Oracle重復(fù)記錄

2010-11-15 14:42:03

Oracle查詢重復(fù)記

2024-10-16 18:09:54

2010-10-13 17:13:17

MySQL重復(fù)記錄

2010-07-02 13:50:11

SQL Server數(shù)

2010-11-25 15:43:02

MYSQL查詢重復(fù)記錄

2010-07-28 13:54:42

Flex數(shù)據(jù)綁定

2022-03-25 14:47:24

Javascript數(shù)據(jù)類型開發(fā)

2023-05-22 08:03:28

JavaScrip枚舉定義
點贊
收藏

51CTO技術(shù)棧公眾號