UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
    SET col_name1=expr1 [, col_name2=expr2 ...]
    [WHERE where_definition]
    [ORDER BY ...]
    [LIMIT row_count]Multiple-table syntax: UPDATE [LOW_PRIORITY] [IGNORE] tbl_name [, tbl_name ...]
    SET col_name1=expr1 [, col_name2=expr2 ...]
    [WHERE where_definition]根据 MySQL Manual 里面的语法, 怎么有 UPDATE ... FROM 的结构??UPDATE 多个表的语法在是第二个.至于你上面的 A 跟 B 有何实质联系??
你又没有 UPDATE B 表的东西, 有何必要挂上 B 表?

解决方案 »

  1.   

    update cms_memberapply 
    set A.flag1='y'
    where
    sGrade in ('大二','大三') 
    and 
    sIsAttendLeague='曾经参与' 
    and 
    fMonthFare>=30不就得了?
    本身你的 B 表不需要更新也没什么实质的东西去至于 A 表的 UPDATE.
      

  2.   

    to Rekcuf(Rik) :
    A表与B表之间有关联啊,A.iId=B.iApplyerId and B.iItemContentId in ('4') 。
      

  3.   

    你给出的多表关联更新的语法与mysql的版本有关吗?还请回复,谢谢!!!
      

  4.   

    A.iId=B.iApplyerId and B.iItemContentId in ('4')这个关联我看到了啊, 但是对于你只需 set A.flag1='y' 的话, 这个关联有何作用?
    这对于 A 表的 SET flag1 = 'y' 没有任何制约啊, 只是单纯的关联起来罢了, 这样做的目的何在? 当然, 如果此时你需要顺带更新 B 表的某个字段, 就可以用上面我说的多表更新语句. 关联语句放在 WHERE 字句中.
    如:UPDATE a, b
    SET a.name = 'Rik', b.age = 21
    WHERE a.uid = b.uid这个多表关联更新与版本无关. 早期的 MySQL 也有啊.
    不过就是没有 UPDATE ... FROM ... 这种语法啦~
      

  5.   

    按下面的写法也不行:
    update cms_memberapply,cms_memberprefer set cms_memberapply.flag1='y' where cms_memberapply.iId=cms_memberprefer.iApplyerId and cms_memberprefer.iItemContentId in (4)
      

  6.   

    Re  yundanfengqing(云淡风轻) :出现什么提示??不好意思, 刚才看错, 这个是需要关联更新. 上面的语句应该没错啊, 提示什么错误?
      

  7.   

    to Rekcuf(Rik) :
    关联
    A.iId=B.iApplyerId and B.iItemContentId in ('4')
    怎么会没有用呢,缩小结果集啊,并不是所有cms_memberapply.flag1都改为'y',而是当这个表中的数据能与cms_memberprefer 中的某些记录对应上上才改。
      

  8.   

    错误信息:
    You have an error in your SQL syntax near 'cms_memberprefer set cms_memberapply.flag1='y' where cms_memberapply.iId=cms_mem' at line 1
      

  9.   

    哈, 把 B.iItemContentId in ('4') 看成 A.iItemContentId in ('4') 了.你的
    update cms_memberapply,cms_memberprefer set cms_memberapply.flag1='y' where cms_memberapply.iId=cms_memberprefer.iApplyerId and cms_memberprefer.iItemContentId in (4)
    出现什么提示?
      

  10.   

    Starting with MySQL 4.0.4, you can also perform UPDATE operations that cover multiple tables: UPDATE items,month SET items.price=month.price
    WHERE items.id=month.id;哈哈, 4.0.4 以后才支持.
      

  11.   

    如果没办法升级 MySQL,
    就分开两个查询来实现咯.