2

Duplicate of "INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"

Community
  • 1
  • 1
user1165454
  • 741
  • 1
  • 6
  • 8

4 Answers4

1
INSERT IGNORE INTO `table` VALUES ("val1"), ("abc")

or

INSERT IGNORE INTO `table` SET columnname1="val1"
Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
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