为什么mysql不执行此更新连接语句

时间:2014-05-27 12:49:15

标签: mysql sql

我希望通过内部联接比较两个表,并通过edit_27_5表列更新表d_family中的列..但是有些错误..我尝试了更多的解决方案,但是ditint运行良好

我看到此消息(#1064 - 您的SQL语法出错;请查看与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在附近使用' SET d_family.city = edit_27_5 .city,SET d_family.fa_name = edit_27_5.fa_n' at line 3

  UPDATE d_family  INNER JOIN edit_27_5
      ON 
  d_family.fa_id  =  edit_27_5.fa_id
  SET d_family.area  =  edit_27_5.area,
  SET d_family.city  =  edit_27_5.city,
  SET d_family.fa_name  =  edit_27_5.fa_name,
  SET d_family.fa_nationality  =  edit_27_5.nath,
  SET d_family.fa_phone_number  =  edit_27_5.phone,
  SET d_family.fa_mobile_number  =  edit_27_5.mobile,
  SET d_family.fa_account_anstaqram  =  edit_27_5.anst,
  SET d_family.fa_account_mail  =  edit_27_5.email,
  SET d_family.fa_account_twitter  =  edit_27_5.twit,
  SET d_family.fa_account_facebook  =  edit_27_5.face,
  SET d_family.fa_product_desc  =  edit_27_5.pt_desc,
  SET d_family.product_type  =  edit_27_5.pt_type,
  SET d_family.fa_markting_type  =  edit_27_5.markting
      WHERE d_family.fa_id  < 7221

1 个答案:

答案 0 :(得分:3)

UPDATE d_family  INNER JOIN edit_27_5
  ON 
  d_family.fa_id  =  edit_27_5.fa_id

您错过了加入部分

d_family.fa_id  =  .fa_id

设置多个时间也是错误的

所以语法是

update table1 t1 
join table2 t2 on t1.id = t2.id
set 
t1.col1 = t2.col1,
t1.col2 = t2.col,
......

在你的情况下它应该是

UPDATE d_family  
INNER JOIN edit_27_5 ON d_family.fa_id  =  edit_27_5.fa_id
SET 
d_family.area  =  edit_27_5.area,
d_family.city  =  edit_27_5.city,
d_family.fa_name  =  edit_27_5.fa_name,
d_family.fa_nationality  =  edit_27_5.nath,
d_family.fa_phone_number  =  edit_27_5.phone,
d_family.fa_mobile_number  =  edit_27_5.mobile,
d_family.fa_account_anstaqram  =  edit_27_5.anst,
d_family.fa_account_mail  =  edit_27_5.email,
d_family.fa_account_twitter  =  edit_27_5.twit,
d_family.fa_account_facebook  =  edit_27_5.face,
d_family.fa_product_desc  =  edit_27_5.pt_desc,
d_family.product_type  =  edit_27_5.pt_type,
d_family.fa_markting_type  =  edit_27_5.markting
WHERE d_family.fa_id  < 7221