{"id":9257,"date":"2018-03-13T05:35:09","date_gmt":"2018-03-13T05:35:09","guid":{"rendered":"http:\/\/www.withdata.com\/blog\/?p=9257"},"modified":"2018-03-13T05:35:09","modified_gmt":"2018-03-13T05:35:09","slug":"upsert-a-row-into-mysql-table","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/mysql\/upsert-a-row-into-mysql-table.html","title":{"rendered":"Upsert  a row Into Mysql Table"},"content":{"rendered":"<p>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 &#8220;ON DUPLICATE KEY UPDATE&#8221;.<\/p>\n<pre>INSERT INTO employees(id, name, hire_date ) \r\nVALUES (1, 'John', '2016-11-29' ) \r\nON DUPLICATE KEY UPDATE name='john', hire_date='2016-11-29'<\/pre>\n<p>In SQL Server,\u00a0<a href=\"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 &quot;replace into&quot;. In SQL Server, https:\/\/www.withdata.com\/blog\/sql-server\/replace-update-or-insert-a-row-into-sql-server-table.html In Oracle, https:\/\/www.withdata.com\/blog\/oracle\/replace-update-or-insert-a-row-into-oracle-table-merge-into.html In DB2, https:\/\/www.withdata.com\/blog\/db2\/replace-update-or-insert-a-row-into-db2-table-merge-into.html In Sqlite, https:\/\/www.withdata.com\/blog\/sqlite\/replace-update-or-insert-a-row-into-sqlite-table.html How to do it in PostgreSQL?\">https:\/\/www.withdata.com\/blog\/sql-server\/replace-update-or-insert-a-row-into-sql-server-table.html<\/a><\/p>\n<p>In Oracle,\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/oracle\/replace-update-or-insert-a-row-into-oracle-table-merge-into.html\">https:\/\/www.withdata.com\/blog\/oracle\/replace-update-or-insert-a-row-into-oracle-table-merge-into.html<\/a><\/p>\n<p>In DB2,\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/db2\/replace-update-or-insert-a-row-into-db2-table-merge-into.html\">https:\/\/www.withdata.com\/blog\/db2\/replace-update-or-insert-a-row-into-db2-table-merge-into.html<\/a><\/p>\n<p>In Sqlite,\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/sqlite\/replace-update-or-insert-a-row-into-sqlite-table.html\">https:\/\/www.withdata.com\/blog\/sqlite\/replace-update-or-insert-a-row-into-sqlite-table.html<\/a><\/p>\n<p>Some MySQL tools you can try: <a href=\"https:\/\/www.withdata.com\/mysql\/\"> https:\/\/www.withdata.com\/mysql\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;ON DUPLICATE KEY UPDATE&#8221;. INSERT INTO employees(id, name, hire_date ) VALUES (1, &#8216;John&#8217;, &#8216;2016-11-29&#8242; ) ON DUPLICATE KEY UPDATE name=&#8217;john&#8217;, hire_date=&#8217;2016-11-29&#8242; In SQL Server,\u00a0https:\/\/www.withdata.com\/blog\/sql-server\/replace-update-or-insert-a-row-into-sql-server-table.html In [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[238,1323,239,428],"class_list":["post-9257","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-merge-into","tag-mysql","tag-replace-into","tag-upsert"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/9257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=9257"}],"version-history":[{"count":1,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/9257\/revisions"}],"predecessor-version":[{"id":9258,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/9257\/revisions\/9258"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=9257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=9257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=9257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}