MySQL - Delete duplicates in a table

December 2016






To remove duplicates in a table set up as follows:

CREATE TABLE IF NOT EXISTS TabTest (   
           prim_key integer(4) NOT NULL auto_increment,
           x integer,
           y integer,
           z integer,
           Constraint pk_Tab_test PRIMARY KEY  (rpim_key)    
); 


We should begin by setting the fields related to duplicate (in our case the fields x and y):



To remove duplicate fields in x and y run the command:
ALTER IGNORE TABLE  TabTest ADD UNIQUE INDEX(x,y);

Related :

This document entitled « MySQL - Delete duplicates in a table » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.