I am working on a conversion and I have run into a problem concerning duplicate rows. I ultimately have to insert the data in the table where the conversion is being done into another table. In the new table three fields make up the primary key. Due to various factors the in the conversion process I end up with multiple rows where the three (primary key) fields are duplicates.
I am using the following code to find the duplicates:
SELECT pkey, COUNT(pkey) AS Expr1
FROM AccountZoneTbl0
GROUP BY pkey
HAVING (COUNT(pkey) > 1)
ORDER BY pkey
pkey is a field that contains a string that consists of the three fields that make up the primary key in the table where the data will be inserted.
From this code I find 160 duplicates most with just 2 copies of the pkey field but some with as many as 10.
I need to delete all but one of these rows. It is important that one remain but the others must go.
Does anybody have any idea as to how I can write a routine that will delete all but one row where the pkey field is duplicated?
Thaks in advance for any assistance you are able to provide.
Ron--
I am using the following code to find the duplicates:
SELECT pkey, COUNT(pkey) AS Expr1
FROM AccountZoneTbl0
GROUP BY pkey
HAVING (COUNT(pkey) > 1)
ORDER BY pkey
pkey is a field that contains a string that consists of the three fields that make up the primary key in the table where the data will be inserted.
From this code I find 160 duplicates most with just 2 copies of the pkey field but some with as many as 10.
I need to delete all but one of these rows. It is important that one remain but the others must go.
Does anybody have any idea as to how I can write a routine that will delete all but one row where the pkey field is duplicated?
Thaks in advance for any assistance you are able to provide.
Ron--