select a.* from test a left join (select a,b,c,d from test group by a,b,c,d having count(*)>1 ) b on a.a=b.a and a.b=b.b and a.c=b.c and a.d=b.d where b.a is not null
select * from test where (a in (select a from test group by a
having count(a)>1))and (b in (select b from test group by b
having count(b)>1))and (c in (select c from test group by c
having count(c)>1))and (d in (select d from test group by d
having count(d)>1))and
增加一个自动增长字段:
alter table table_name add IDFIELD integer identity(1,1)
,删除重复记录
delete from table_name a
where IDFIELD< (select max(IDFIELD) from table_name
where column1=a.column1 and column2=a.column2
and colum3=a.colum3 and ...);
最后执行
alter table table_name drop column IDFIELD 删除增加的字段。
方法2:
创建临时表
select distinct * into tmp_table_name from table_name
然后,truncate table table_name
最后,insert into table_name select * from tmp_table_name