Brian,
I'm not sure that would work if Field1 is not the PK. What Leon is saying,
if I understand him correctly, is he has 3 fields in the table and they are
effectively the PK. So it would be something along the lines of:
SELECT Field1 + Field2 + Field3 FROM MyTable
GROUP BY Field1 + Field2 + Field3 HAVING COUNT(*) > 1
ORDER BY Field1,Field2,Field3
That will give you one copy of each duplicate; then, for each duplicate I'd
probably save the 3 field values, delete each group of records in the
underlying table and then re-insert one record:
/* Inside a loop scanning through the above result */
@@FieldOne = Field1
@@FieldTwo = Field2
@@FieldThree = Field3
DELETE FROM MyTable WHERE Field1 = @@FieldOne AND Field2 = @@FieldTwo AND
Field3 = @@FieldThree
INSERT INTO MyTable (Field1,Field2,Field3) VALUES
(@@FieldOne,@@FieldTwo,@@FieldThree)
.... but, I'd wrap all that in a transaction for safety, to be on the safe
side.
And of course, experiment on a copy of the original table for safety's sake.
--Bob
Brian P. Hammer said:
You can use the duplicate record query in Access to find them.
You can create an Access table matching the one with the duplicates and then
set on field as no duplicates and import the records. This will remove the
duplicate records.
Or using code:
SELECT Table1.Field1, Table1.ID
FROM Table1
WHERE (((Table1.Field1) In (SELECT [Field1] FROM [Table1] As Tmp GROUP BY
[Field1] HAVING Count(*)>1 )))
ORDER BY Table1.Field1;
And then just execute a delete but be careful, this returns all duplicate
records not just the duplicates of x
HTH,
--
Brian P. Hammer
Leon said:
I have a table that has more than 1 milion rows so practically it is
impossible to remove all duplicate rows by hand.
Could you help me to remove those duplicate rows at all?
This table doesn't have primary key( identity ) column.
Say Table name => MyTable
Column => Col1,Col2,Col3
No primary key column here.
Thanks a lot in advance.