Syntax error “near FROM” when using UPDATE with JOIN in MySQL?

南笙酒味 提交于 2019-12-10 14:11:21

问题


UPDATE bestall SET view = t1.v, rawview = t1.rv 

FROM bestall INNER JOIN beststat as t1

ON bestall.bestid = t1.bestid

this query gives syntax error near

 'FROM bestall INNER JOIN beststat as t1 ON bestall.bestid = t1.bestid' at line 3

any reasons?


回答1:


That isn't valid MySQL syntax. It is valid in MS SQL Server, however. For MySQL, use:

UPDATE 
  bestall
  JOIN beststat AS t1 ON bestall.bestid = t1.bestid 
SET view = t1.v, rawview = t1.rv

MySQL requires the update tables to come before the SET clause. See the MySQL UPDATE syntax reference for full details.




回答2:


Try it this way:

UPDATE bestall INNER JOIN beststat as t1
ON bestall.bestid = t1.bestid SET view = t1.v, rawview = t1.rv 


来源:https://stackoverflow.com/questions/10262300/syntax-error-near-from-when-using-update-with-join-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!