Upsert a row Into Mysql Table


In Mysql, if you want to either updates or inserts a row in a table, depending if the table already has a row that matches the data, you can use “ON DUPLICATE KEY UPDATE”.

INSERT INTO employees(id, name, hire_date ) 
VALUES (1, 'John', '2016-11-29' ) 
ON DUPLICATE KEY UPDATE name='john', hire_date='2016-11-29'

In SQL Server,

In Oracle,

In DB2,

In Sqlite,

Some MySQL tools you can try: