Insert on duplicate key update leaves unmentioned columns unchanged on update but gives them default values on insert. with replace into, unmentioned columns always get default values, never existing values.. The statement above sets the value of the c1 to its current value specified by the expression values(c1) plus 1 if there is a duplicate in unique index or primary key. mysql insert on duplicate key update example. let’s take a look at an example of using the insert on duplicate key update to understand how it works.. The on duplicate key update clause can contain multiple column assignments, separated by commas. in assignment value expressions in the on duplicate key update clause, you can use the values(col_name) function to refer to column values from the insert portion of the insert on duplicate key update statement..
Description: when insert on duplicate key update executes the update statement instead of the insert statement, last_insert_id() gets incremented as if a row was added to the table, even though no such thing happened.. When updating summary tables we typically use on duplicate key update, a mysql extension to insert statements since version 4.1, that allows a record to either be inserted or updated in one query. for example, with this table:. In mysql, if you specify on duplicate key update and a row is inserted that would cause a duplicate value in a unique index or primary key, an update of the old row is performed. for example, if column a is declared as unique and contains the value 1, the following two statements have identical effect:.