多种删除重复记录语句

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
リリース: 2016-06-07 17:47:28
オリジナル
1123 人が閲覧しました

多种删除重复记录语句
1. 删除全部重复记录(慎用)

delete 表 where 重复字段 in (select 重复字段 from 表 group by 重复字段 having count(*)>1)

2. 保留一条(这个应该是你所需要的)
delete hzt where id not in (select max(id) from hzt group by title)
注:此处保留id最大一条记录

select distinct * into #temp from 表
truncate table 表
insert 表 select * from #temp
drop table


--
带有标识列
--备份数据

select * into #temp from 表
alter table #temp drop column id

--删除原表数据

truncate table msgtable

--恢复数据并去掉重复数据
insert into 表 select distinct * from #temp

--

delete from aa where a in ( select a from aa group by a having count(a)>1)


--

alter table 表 add newfield int identity(1,1)

delete 表

where newfield not in(select min(newfield) from 表 group by 除newfield外的所有字段)

alter table 表 drop column newfield


--
--添加一个处理的标识字段
alter table 表 add id int identity(1,1)
go
   
--删除重复记录
delete a

from 表 a left join(select id=min(id) from 表 group by a,b)b on a.id=b.id

where b.id is null
go

--删除处理用的标识字段
alter table 表 drop column id?>

関連ラベル:
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
多対多の関係の例
から 1970-01-01 08:00:00
0
0
0
多くのビデオが点滅しています
から 1970-01-01 08:00:00
0
0
0
非常に多くの質問
から 1970-01-01 08:00:00
0
0
0
内容が多すぎる
から 1970-01-01 08:00:00
0
0
0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート