MySQL - Delete duplicates in a table

June 2017






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


Published by jak58. Latest update on July 20, 2009 at 04:53 AM by jak58.
This document, titled "MySQL - Delete duplicates in a table," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).