Skip to main content
1 of 4

I would agree with @BillThot that what you want to do may crate some problems for but what you need is ON DUPLICATE KEY UPDATE statement so your query would be something like this:

INSERT INTO table1
(`title`, `abr`, `name`) 
VALUES
('title', 'abr', 'name')
ON DUPLICATE KEY UPDATE `title` = CONCAT(`title`, '-2');

You can change CONCAT to any other function or your own stored procedure.

In this typical example, all three columns are UNIQUE. When the INSERT fails, I do not know which col caused the error to change its corresponding value.

If all three columns have unique index it means that there are no single one which caused the error as there is record with all three columns having exactly the same values you want to insert.