1

UPDATEdoubleで実行しようとしていますINNER JOINが、次のエラーが発生します。

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM pro_users AS u INNER JOIN cAlerts AS c ON c.user_id = u.user_id I' at line 3

これが私のmysqlコードです:

 UPDATE u 
  SET u.active_member = 0
  FROM pro_users AS u
  INNER JOIN cAlerts AS c
   ON c.user_id = u.user_id
  INNER JOIN srAlerts AS s  
   ON s.user_id = c.user_id
  WHERE c.status=0  
  AND s.active=0 
  AND u.active_member = 1

私のエラーを見つけることができますか?

4

3 に答える 3

1

これを試すことができますか:

UPDATE 
    pro_users AS u
SET
    u.active_member = 0
WHERE
    u.active_member = 1 
    AND
    (
        SELECT c.user_id
        FROM cAlerts AS c
        WHERE c.user_id = u.user_id AND c.status = 0
        LIMIT 1
    ) IS NOT NULL 
    AND
    (
        SELECT s.user_id
        FROM srAlerts AS s
        WHERE s.user_id = u.user_id AND s.active = 0
        LIMIT 1
    ) IS NOT NULL
于 2013-08-28T19:30:34.357 に答える
1

これは、更新を行う ISO/ANSI SQL の方法です。

update pro_users u set active_member = 0
where u.active_member = 1
  and exists ( select *
               from cAlerts c
               where c.user_id = u.user_id
                 and c.status  = 0
             )
  and exists ( select *
               from srAlerts sr
               where sr.user_id = u.user_id
                 and sr.active = 0
             )

私の知る限りfrom、ステートメント内の結合の有無にかかわらず、節updateは Microsoft/Sybase Sql Server の異常です。

注記に編集: http://dev.mysql.com/doc/refman/5.0/en/update.htmlの mySql マニュアルで少し調べてみると、一部の SQLFiddling はこれが機能すると述べています。

update pro_users u
join cAlerts  c  on c.user_id  = u.user_id and c.status  = 0
join srAlerts sr on sr.user_id = u.user_id and sr.active = 0
set active_member = 0
where u.active_member = 1
于 2013-08-28T19:52:14.777 に答える
0

私はこれがうまくいくと思います:

UPDATE pro_users AS u
INNER JOIN cAlerts AS c
   ON c.user_id = u.user_id AND c.status=0
INNER JOIN srAlerts AS s  
   ON s.user_id = c.user_id AND s.active=0
SET u.active_member = 0
WHERE u.active_member = 1
于 2013-08-28T19:34:54.603 に答える