Duplicate of "INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"
Asked
Active
Viewed 65 times
4 Answers
1
INSERT IGNORE INTO `table` VALUES ("val1"), ("abc")
or
INSERT IGNORE INTO `table` SET columnname1="val1"

Karoly Horvath
- 94,607
- 11
- 117
- 176
-
ahh sorry, it's a bit early in the morning *grin* – Karoly Horvath Feb 19 '12 at 10:34
0
Check your table first if the pair of values already exists. If it does simply don't make the insert.

Jan Hančič
- 53,269
- 16
- 95
- 99
0
three things you can do.
- You can check before insert if the key pair already exists.
- Look at INSERT IGNORE syntax
- You can wrap your code in try catch if you are using PDO to override this error. I personally am not in favor of this but works great

Jaspreet Chahal
- 2,759
- 1
- 15
- 17
0
You can use INSERT IGNORE. No need to check anything - it brings additional overhead.

Roman Newaza
- 11,405
- 11
- 58
- 89