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

六種SQL Server刪除重復(fù)行的方法

數(shù)據(jù)庫 SQL Server
SQL Server數(shù)據(jù)庫中如果要刪除重復(fù)行數(shù)據(jù),應(yīng)該如何操作呢?下面就教您六種SQL Server刪除重復(fù)行的方法,希望對您能有所幫助。

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

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

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

group   by   子句后跟的字段就是你用來判斷重復(fù)的條件,如只有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   子句后跟的字段就是你用來判斷重復(fù)的條件,如只有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  

以上就是SQL Server刪除重復(fù)行的方法介紹。

 

 

 

【編輯推薦】

SQL Server創(chuàng)建表語句介紹

SQL Server創(chuàng)建數(shù)據(jù)庫的命令

SQL SERVER連接失敗的解決方案

帶您了解SQL Server游標(biāo)

SQL Server權(quán)限的分配管理

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

2011-09-13 15:51:54

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

2011-03-08 08:59:01

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

2022-05-25 09:55:40

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

2010-09-01 16:47:18

SQL刪除

2009-04-20 15:54:04

SQL Server重復(fù)行

2010-06-28 12:46:09

SQL Server

2010-11-10 11:27:40

SQL Server重

2010-10-08 11:13:22

MySQL修改密碼

2020-12-15 10:54:22

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

2011-02-24 10:56:34

人才

2010-09-03 09:49:39

SQL刪除

2017-10-27 11:47:05

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

2010-07-01 12:29:27

SQL Server重

2011-06-23 18:57:10

網(wǎng)站推廣

2023-06-01 16:45:11

React開發(fā)JavaScript

2020-10-27 10:33:01

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

2010-07-12 09:52:24

刪除 SQL Serv

2016-09-01 14:04:51

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

2023-04-26 08:41:16

Git撤消更改

2023-04-03 20:29:00

Linux環(huán)境變量
點(diǎn)贊
收藏

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