Subject Re: [maybe OT] deleting duplicates
Author Dimitry Sibiryakov
On 27 Nov 2002 at 12:21, duilio_fos wrote:

>Due to a program error, I have duplicated rows in table T that have
>the same value in Column1, while it should be unique.
>
>If N is the number of rows that share the same value in Column1, I
>need to delete N-1 of them.
>
>Column2 is unique for every row in T.

Quote from www.ibase.ru: "Deleting duplicate rows"

Diane Brown
Cognos

DELETE FROM XXX T1 WHERE EXISTS
(SELECT * FROM XXX T2 WHERE
(T2.column1 = T1.column1 or (T2.column1 is null and T2.column1 is
null)) AND
(T2.column2 = T1.column2 or (T2.column2 is null and T2.column2 is
null)) AND
(.......) AND
T2.RDB$DB_KEY > T1.RDB$DB_KEY))

Use '<' if you want to keep first row.

In your case all may be simlier:

DELETE FROM T t1 WHERE EXISTS
(SELECT * FROM T t2 WHERE t1.Column1=t2.Column1 AND
t1.Column2>t2.Column2)

SY, Dimitry Sibiryakov.