Subject Re: [firebird-support] finding duplicates in a table
Author Lester Caine
matt_kopf wrote:

> I am trying to set a primary key on a table that is already popluated.
> The table has more than 5000 records in it, and when I set the primary
> key I get an error that says there are duplicate values in the table.
> What I need is a sql statement that will show me what records in the
> table are duplicated. This is what I have come up with so far in my
> testing

SELECT FIELD FROM TABLE
GROUP BY FIELD
HAVING COUNT( FIELD ) > 1

> but it returns all the records as well as the duplicate ones. I am
> very new at SQL so the reason for this is a Mystery to me! The script
> above is just a sample that I was testing with. In the real table
> there are 6 fields and 5 of them are for the new primary key. Any help
> would be great!!!

Five fields should not be in the primary key. They could be a unique
index, but use something easier for identifying individual records.

--
Lester Caine
-----------------------------
L.S.Caine Electronic Services