14 Ağustos 2007 Salı

Oracle DB de tekrarlanan kayitlari silme

Asagidaki örnekde TestTable da min rowid ye sahip olan kayit saklanacak geri kalan tekrarlanan kayitlar silinecek.

Delete from TestTable t1
where t1.rowid >
(Select min(t2.rowID) from TestTable t2
where t1.col1 = t2.col1
and t1.col2 = t2.col2)

Benzer bir cözüm sql server icin söyle olabilir:

Oracle daki "rowid" yerine tablomuzun birincil anahtarini (PK) kullanabiliriz.
PK: sysID

Delete from TestTable where sysID IN (
Select sysID from TestTable t1
where t1.sysID > (Select min(t2.sysID) from TestTable t2
where t1.col1 = t2.col1
and t1.col2 = t2.col2))

Hiç yorum yok: