Set a UNIQUE on any column that must be unique, or a combination of columns.
For instance:
ALTER TABLE `TableName` ADD UNIQUE `constrain_me` (`column1`, `column2`);
If you want to ignore any error that a duplicate insert may indicate, use INSERT IGNORE , although you might want to catch this error rather than cleaning it under the carpet.
source share