Subject Re: [firebird-support] removing duplicate records
Author Alexandre Benson Smith
Hi Alan,

alan davies wrote:

>Arno - Thanks for the advice, but this does not work. I get the sql
>hourglass and windows task manager shows cpu at 100% with ibexpert not
>responding. All I can do is end the task (this is the same on another
>machine trying ibconsole) because the system is unresponsive.
>
>Alan J Davies
>Aldis
>Tel: +44(0)1926 842069
>Fax: +44(0)1926 843755
>
>
>
>
Try this one:

DELETE FROM
Supplier s1
WHERE
RecordID <> (SELECT Min(RecordID) FROM Supplier s2 WHERE s2.Weigh_Code = s1.Weigh_Code)

you could create an index on Weigh_Code, I think will speed it up.

Another way:
Mark the records that will be kept and delete the others.

like this:

Alter table Supplier add Foo char(1);
commit;

Update
Supplier s1
set
foo = '1'
where
RecordID = (SELECT Min(RecordID) FROM Supplier s2 WHERE s2.Weigh_Code = s1.Weigh_Code);

Delete from Supplier where Foo Is Null;

After you are sure that only the records you want are on the table...

commit;
Alter table Supplier drop Foo;
commit;


HTH

--

Alexandre Benson Smith
Development
THOR Software e Comercial Ltda.
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br