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

總結:六種刪除數(shù)據(jù)庫重復行的方法

數(shù)據(jù)庫
SQL Server刪除重復行是我們最常見的操作之一,下面就為您介紹六種適合不同情況的SQL Server刪除重復行的方法,供您參考。

SQL Server刪除重復行是我們最常見的操作之一,下面就為您介紹六種適合不同情況的SQL Server刪除重復行的方法,供您參考。

1.如果有ID字段,就是具有唯一性的字段

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

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

2. 如果是判斷所有字段也可以這樣

  1. select   *   into   #aa   from   table   group   by   id1,id2,....      
  2. delete   table        
  3. insert   into   table        
  4. select   *   from   #aa  

3. 沒有ID的情況

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

4. col1+','+col2+','...col5 聯(lián)合主鍵

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

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

5.

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

6.

  1. select   distinct   *   into   #temp   from   tablename        
  2. delete   tablename        
  3. go      
  4. insert   tablename   select   *   from   #temp   Sqlclub    
  5. go      
  6. drop   table   #temp  

原文鏈接:http://www.cnblogs.com/zhangshufeng/archive/2011/09/05/2167079.html

【編輯推薦】

  1. 養(yǎng)成一個SQL好習慣帶來一筆大財富
  2. 告訴你,如何成就DBA職業(yè)生涯
  3. SQL Server性能調(diào)優(yōu)之淺析SQL執(zhí)行的過程
  4. 客戶的一次疏忽,DBA的一次噩夢
  5. 數(shù)據(jù)庫點滴之精妙SQL語句

 

 

 

責任編輯:艾婧 來源: 自 慎的博客
相關推薦

2010-10-22 16:29:11

SQL Server刪

2022-05-25 09:55:40

數(shù)據(jù)重復提交Java

2011-07-28 16:39:03

MySQL數(shù)據(jù)庫修改MySQL密碼

2011-03-08 08:59:01

SQL Server數(shù)數(shù)據(jù)移動

2017-10-27 11:47:05

SQL數(shù)據(jù)庫優(yōu)化

2011-01-12 21:26:49

2011-05-24 10:54:15

數(shù)據(jù)庫重復數(shù)據(jù)刪除

2019-05-06 15:27:48

Oracle數(shù)據(jù)庫數(shù)據(jù)

2018-04-27 13:00:00

數(shù)據(jù)庫MySQL刪除重復行

2019-05-16 13:00:18

異步編程JavaScript回調(diào)函數(shù)

2023-09-06 08:00:00

ChatGPT數(shù)據(jù)分析

2023-08-15 15:44:55

React開發(fā)

2023-06-01 16:45:11

React開發(fā)JavaScript

2011-02-24 10:56:34

人才

2010-04-13 10:15:17

Oracle數(shù)據(jù)庫

2010-09-01 16:55:55

SQL刪除連接

2016-09-01 14:04:51

數(shù)據(jù)中心

2011-03-14 15:47:33

Oracle數(shù)據(jù)庫

2020-10-27 10:33:01

物聯(lián)網(wǎng)

2010-10-08 11:13:22

MySQL修改密碼
點贊
收藏

51CTO技術棧公眾號