user1094081
user1094081

Reputation:

MySQL on duplicate key update without updating the recorded row

I read about the MySQL command ON DUPLICATE KEY UPDATE. I have a column Surnames in a Users table. Since there must be no identical surnames, I want to INSERT a new surname when the surname isn't in the database, and leave the row as it was recorded if the surname was previously saved in the database, without updating it. How can I achieve this?

Upvotes: 1

Views: 159

Answers (1)

Filip Roséen
Filip Roséen

Reputation: 63797

INSERT IGNORE ... will try to insert a new row, if a duplicate key is found the new data will be discarded.

Documentation of INSERT

Upvotes: 2

Related Questions