Add a unique index to your table in columns col1, col2 and col2 like this.
ALTER TABLE `main` ADD UNIQUE INDEX `col1_col2_col3` (`col1`, `col2`, `col3`);
And this will prevent duplicate rows from being inserted into your table.
For example: After you enter these values,
INSERT INTO `main` (`col1`, `col2`, `col3`) VALUES (1, 11, 111);
You cannot insert this, you will get duplicate row error
INSERT INTO `main` (`col1`, `col2`, `col3`) VALUES (1, 11, 111);
With the right unique indexes, you donโt have to worry about duplicate entries later.
source share