Use MySQL ON DUPLICATE KEY UPDATE to update data in insert SQL statement

If you get a SQL dump of a database table and want to update part of the data into existing table, you can use the following SQL statement to achieve it.

INSERT INTO `t_products` (`productid`, `prodname_en`, `proddesc_en`) VALUES(222, ‘This is the product name’, ‘This is the product description’) ON DUPLICATE KEY UPDATE some_column1=VALUES(prodname_en), some_column2=VALUES(proddesc_en);


Leave a Reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.