Many times, duplicate data exists in tables that we would rather ignore. So, doing a SELECT for example would return the duplicate data, when in fact that would be a bit of a problem for us. mybloggingplanet.com

One way to get around this is to get MySQL to ignore the duplicate records, which can be done with the command

ALTER IGNORE TABLE testtable ADD UNIQUE INDEX(col1,col2);

What this does is creates an index on two columns in the table, getting unique rows for that index, and ignoring any additional rows that match. This won’t check the entire table for a match, but only those two columns, so it might leave out useful rows if you are not careful with which columns you select in the index.

If all is working as it should, the resulting queries on this table should return back the data, excluding duplicates.

Share