刪除表中重複資料

2021-05-23 02:12:19 字數 354 閱讀 6316

刪除表中重複資料

//取出line_fancy2表中fancy_name相同的最小fancy_id 寫進tmp表

create table tmp as select min( fancy_id ) as col1

from line_fancy2

group by fancy_name;

//刪除line_fancy2中fancy_id不在tmp表中的所有資料

delete from line_fancy2 where fancy_id not in (

select col1

from tmp

);//刪除臨時表

drop table tmp;

刪除表中重複資料

如果重複資料很多,被刪掉的可能是大部分記錄,業務又允許的情況下,可以考慮重建表 create table newtable as select distinct from table rename table to oldtable rename newtable to table create i...

Oracle刪除表中重複資料

1.建立臨時表 備份全部資料到 create table tmap.t comm customer col log 731all as select from tmap.t comm customer col log 2.建立臨時表 備份資料 去除重複項 create table tmap.t co...

Mysql刪除表中重複資料

一張表中有重複資料,需要刪除重複的資料,只保留 最大 最小 一條。例 現有a表 id 主鍵 唯一 b 資料 有重複 需求 刪除表中重複的資料,保留相同資料中id最小的資料。效果 sql思路 先查詢出去重過後的id 可用分組 再刪除其它id的資料 delete from a where id not ...