如何在重复密钥更新到mysql表中插入?

时间:2015-11-17 10:00:55

标签: php mysql codeigniter

我有一张与另一张桌子有关的桌子。我需要插入ID并更新重复键插入。下面是我插入表中的查询,但给出了语法错误。将插入多行 (88,90709),(88,90710),..

 Error Number: 1064

 You have an error in your SQL syntax; check the manual that corresponds     to your MySQL server version for the right syntax to use     near '90713), business_id= VALUES(88)' at line 3

INSERT INTO business_service_coverage (business_id, area_id) VALUES (88,90713) ON DUPLICATE KEY UPDATE area_id = VALUES(90713), business_id= VALUES(88)

表格结构

 1) id  primary key auto increment
 2) busienss_id not unique
 3) area_id int 

1 个答案:

答案 0 :(得分:0)

您的syntax指定错误,请尝试以下

INSERT INTO business_service_coverage (business_id, area_id) VALUES (88,90713) 
ON DUPLICATE KEY UPDATE area_id = 90713, business_id= 88;