6 个解决方案
#1
如果完全相同的话,除了faq里面的方法,你还可用distinct把数据找出来然后查到一个临时表,然后删除源表的那些数据,再把临时表的数据插回去。
#2
select * from a
where ax in (select ax from a group by ax having count(ax) > 1)
#3
--保留一条(这个应该是大多数人所需要的 ^_^)
Delete a Where ID Not In (Select Max(ID) From a Group By Title)
#4
declare @t table(id int);
insert into @t
select 1 union all
select 2 union all
select 3 union all
select 2 union all
select 1
;with c1 as
(
select row_number() over(partition by id order by id) rowid,
id
from @t
)
delete from c1 where rowid > 1
select * from @t order by id
id
-----------
1
2
3
(3 行受影响)
#5
用distinct 最简单了。不过显示最新插入的也行,
select id,f1,f2 from t tt
where tt.id=
(select max(id)
from t
where tt.f1=t.f1 and tt.f2=t.f2)
select id,f1,f2 from t tt
where tt.id=
(select max(id)
from t
where tt.f1=t.f1 and tt.f2=t.f2)
#6
谢谢你!
#1
如果完全相同的话,除了faq里面的方法,你还可用distinct把数据找出来然后查到一个临时表,然后删除源表的那些数据,再把临时表的数据插回去。
#2
select * from a
where ax in (select ax from a group by ax having count(ax) > 1)
#3
--保留一条(这个应该是大多数人所需要的 ^_^)
Delete a Where ID Not In (Select Max(ID) From a Group By Title)
#4
declare @t table(id int);
insert into @t
select 1 union all
select 2 union all
select 3 union all
select 2 union all
select 1
;with c1 as
(
select row_number() over(partition by id order by id) rowid,
id
from @t
)
delete from c1 where rowid > 1
select * from @t order by id
id
-----------
1
2
3
(3 行受影响)
#5
用distinct 最简单了。不过显示最新插入的也行,
select id,f1,f2 from t tt
where tt.id=
(select max(id)
from t
where tt.f1=t.f1 and tt.f2=t.f2)
select id,f1,f2 from t tt
where tt.id=
(select max(id)
from t
where tt.f1=t.f1 and tt.f2=t.f2)
#6
谢谢你!