mysql - Find duplicates on multiple columns in a SQL table in order to create UNIQUE index -
i created index called abc
on table called table
primary key
called id
, 3 others int
columns a
, b
, c
can null
.
now need index unique, tried :
alter table table drop index abc, add unique abc (a, b, c);
but have duplicates, mysql answers :
#1062 - duplicate entry '1-2-3' key 'abc'
i have lot of duplicates, i'm looking easy way search & destroy them all. first guess has been :
select * table group abc
but sadly seems can't group indexes.
is there easy way find duplicates, keep 1 line of each duplicate , delete others ?
edit :
table
id
fieldprimary key
a
,b
,c
int
, cannull
no need eliminate duplicates first, use ignore
option alter table
want;
alter ignore table table drop index abc, add unique abc (a, b, c);
if ignore not specified, copy aborted , rolled if duplicate-key errors occur. if ignore specified, 1 row used of rows duplicates on unique key. other conflicting rows deleted.
...and remember data before running potentially destructive sql random people on internet.
Comments
Post a Comment