Insert or update in MySQL (similar to Oracle's merge statement), oraclemerge
If the record does not exist in MySQL, insert the statement. If the record does not exist, update the statement. You can use the following statement:
Update a field:
Insert into tbl (columnA, columnB, columnC) VALUES (, 3) on duplicate key update columnA = IF (columnB>, columnA)
Update multiple fields:
Insert into tbl (columnA, columnB, columnC) VALUES (, 3) on duplicate key update columnA = IF (columnB>, columnA), columnB = IF (columnC>, columnB), columnC = IF (columnA> 0, 1, columnC );
Because MySQL has optimized the update to the original same value, when it is updated to the original same value, it does not actually update the field, and there is no performance problem.
For more information, visit the following English site:
Https://thewebfellas.com/blog/conditional-duplicate-key-updates-with-mysql