0

I want to delete duplicate records from table. The table does not have primary key (ID), so answers like this are not suitable.

Here is my try:

DELETE FROM afscp_permit
USING afscp_permit, afscp_permit AS vtable
WHERE (NOT afscp_permit.field_name=vtable.field_name)
AND (afscp_permit.field_name=vtable.field_name)
Community
  • 1
  • 1
chaya
  • 423
  • 3
  • 11
  • 19

2 Answers2

0

Following might help if there is no bug in your DBMS and no constraints are in the way:

ALTER IGNORE TABLE afscp_permit ADD UNIQUE INDEX field_name_index (field_name );
Basilevs
  • 22,440
  • 15
  • 57
  • 102
0

How about creating a temporary table with the same columns and doing:

INSERT INTO temp SELECT DISTINCT * FROM afscp_permit;
DELETE FROM afscp_permit;
INSERT INTO afscp_permit SELECT * FROM temp;
DROP TABLE temp;
David Lopez
  • 353
  • 4
  • 13