简体   繁体   中英

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

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?

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.

Try it this way:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM