2017-08-05 215 views
2

如何刪除重複記錄?Firebird SQL刪除重複記錄

我使用此查詢,但它刪除太多。

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

我想刪除兩列公用的記錄。

look this picture

+0

你需要檢查組計數在這裏,不是會太寬泛。 –

+0

你能舉個例子嗎? –

+0

也許只有'HAVING COUNT(sn)> 1'丟失,或者多於一次存在。 – Myonara

回答

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