Firebird Sql删除重复记录

时间:2017-08-05 14:51:45

标签: sql duplicates firebird sql-delete

如何删除重复记录?

我使用此查询,但删除的内容过多。

delete from adaparselkomsulari
where sn not in (select min(sn)
                 from adaparselkomsulari
                 group by sinirtipi, komsuadi);

我想删除两列共有的记录。

look this picture

1 个答案:

答案 0 :(得分:0)

这个怎么样?

delete from adaparselkomsulari a1
    where exists(select first 1 1 from adaparselkomsulari a2
                 where a2.sinirtipi = a1.sinirtipi and  a2.komsuadi=a1.komsuadi 
                 and a1.sn<>a2.sn)

delete from adaparselkomsulari a1
    where (select count(*) from adaparselkomsulari a2
                 where a2.sinirtipi = a1.sinirtipi and  a2.komsuadi=a1.komsuadi)>1