簡體   English   中英

sql更新與內部聯接和哪里

[英]sql update with inner join and where

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服務器版本對應的手冊以獲取正確的語法,以在第3行“ FROM newsreactions INNER JOIN用戶ON newsreactions.memberId = users.id WHERE u”附近使用

雖然不知道。 如果我替換update並通過select set ,則效果很好。

錯誤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實際上是數字值。 如果是這樣,請勿使用單引號。

join子句應位於set子句之前,並且MySQL中不應有from子句:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM