内部联接的sql更新和

时间:2016-09-16 21:15:50

标签: mysql sql sql-update syntax-error

UPDATE newsreactions
SET newsreactions.enabled = '0'
FROM newsreactions
INNER JOIN users ON newsreactions.memberId = users.id
WHERE users.active =  '0' AND users.comment LIKE  '%spam%'

出于某种原因,我收到语法错误:

  

1064 - 您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以便在'FROM newsreactions INNER JOIN用户附近使用正确的语法ON newsreactions.memberId = users.id WHERE u'在第3行

虽然无法理解。 如果我将updateset替换为select,则可以正常使用。

2 个答案:

答案 0 :(得分:5)

错误1064是MySQL语法错误。正确的MySQL语法是:

UPDATE newsreactions nr INNER JOIN
       users u
       ON nr.memberId = u.id
    SET nr.enabled = 0
WHERE u.active =  0 AND u.comment LIKE '%spam%';

注意:

  • JOIN符合UPDATE条款。
  • 表别名使查询更容易编写和阅读。
  • 我猜测enabledactive确实是数字值。如果是这样,请不要使用单引号。

答案 1 :(得分:1)

Obj = { "elements":[ {"name":"something","id":"v1-234"}, {"name":"somethingElse","id":"v1-239"} ], "paging":{ "next" : "100", "total": "2000" }, "linked"={ "partners":[ {"id":"82","name":"A"}, {"id":"83","name":"B"} ], "instructors": [ {"id":"11232","name":"alex"}, {"id":"11432","name":"boob"} ] } } 子句应该在join子句之前,并且MySQL中不应该有set子句:

from