oracle中刪除重覆記錄,有好幾種方法。
第一種:把原來表中的資料都轉存到乙個臨時表中,用distinct查詢出要存到臨時表去的資料。
create table temp_table as select distinct * from table
不過這種方法只適用於表中每一列都相同的情況。
第二種:利用oracle中rowid唯一的特性。比如tablea有id,name,age三列。要刪除表中name,age重複的資料時,則第一種方法就不適用了。
delete from tablea t1
where t1.rowid not in
(select max(rowid) from tablea t2 group by t2.name, t2.age)
第三種:
delete from tablea
where rowid in (select row_id
from (select rowid row_id,tablea.*,
row_number() over(partition by name, age order by rowid) rn
from tablea ) where rn <>1)
第三種和第一種差不多。
Oracle SQL查詢刪除重覆記錄
oracle sql查詢刪除重覆記錄有兩種方式一種是建立乙個臨時表,就不做說明了.另一種是用oracle的rowid來刪除 create table student name varchar 12 姓名 varchar2 2 性別 表已建立.sql insert into student value...
刪除重覆記錄
我們經常在資料庫中有重複的記錄這時候我們希望刪除那些重複的記錄 你不要告訴我你是一條條手動刪除的哈 select distinct into newtable form 程式設計客棧nbsp tablename drop table tabwww.cppcns.comlename select in...
SQL查詢重覆記錄,刪除重覆記錄
1 查詢表中多餘的重覆記錄,重覆記錄是根據單個字段 docid 來判斷 select from tablename where docid in select docid from tablename group by docid h ing count docid 1 例二 select from...