佳丽斯 加厚双人/单人秋冬被子暖冬 羊毛被芯羊毛柔丝被特价包邮 忧忧鱼冬外穿打底裤女秋冬厚长裤女裤加绒加厚高腰弹力铅笔裤靴裤 韩国代购2013新款 韩版秋冬休闲女时尚磨破口袋卫衣韩版学生装 潮

有时,退一步,能一口气进几步,只是这先退一步需要勇气和自信。

用心爱你,努力工作。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  70 随笔 :: 1 文章 :: 33 评论 :: 0 Trackbacks

mysql> UPDATE EACONTACTGROUPS A

SET GROUPNAME=(SELECT CONCAT(B.GROUPNAME,'-',A.GROUPNAME) FROM EACONTACTGROUPS B WHERE B.CORPID=A.CORPID AND B.USERID=A.USERID AND B.GROUPID=A.PARENTGROUPID)

WHERE A.PARENTGROUPID IS NOT NULL;

ERROR 1093 (HY000): You can't specify target table 'A' for update in FROM clause

上面是目前MYSQL5.0仍然有的限制,文档中说:

  • In general, you cannot modify a table and select from the same table in a subquery. For example, this limitation applies to statements of the following forms:

    DELETE FROM t WHERE ... (SELECT ... FROM t ...);UPDATE t ... WHERE col = (SELECT ... FROM t ...);{INSERT|REPLACE} INTO t (SELECT ... FROM t ...);

    Exception: The preceding prohibition does not apply if you are using a subquery for the modified table in the

    FROM

    clause. Example:

    UPDATE t ... WHERE col = (SELECT (SELECT ... FROM t...) AS _t ...);

    Here the prohibition does not apply because a subquery in the

    FROM

    clause is materialized as a temporary table, so the relevant rows in

    t

    have already been selected by the time the update to

    t

    takes place. 依据文档,改成下面的样子就行了:

    mysql> UPDATE EACONTACTGROUPS A

  • SET GROUPNAME=(SELECT CONCAT(B.GROUPNAME,'-',A.GROUPNAME) FROM ( SELECT GROUPNAME,CORPID,USERID,GROUPID,PARENTGROUPID FROM EACONTACTGROUPS) B

    WHERE B.CORPID=A.CORPID AND B.USERID=A.USERID AND B.GROUPID=A.PARENTGROUPID)

    WHERE A.PARENTGROUPID IS NOT NULL;

    Query OK, 16 rows affected (0.01 sec)

    Rows matched: 16 Changed: 16 Warnings: 0

    注:今天写一个删除语句时找到的一点资料.解决了一个简单的删除语句.呵呵,以后注意了,

    原句:delete  from menu_item  where parent_id =(select menu_item_id from menu_item where menu_data like '%manageVendors%');

    修改后:delete  from menu_item  where parent_id =(select temp.menu_item_id from (select m.menu_item_id,m.menu_data from menu_item m) temp where temp.menu_data like '%manageVendors%');

    posted on 2010-01-28 12:56 王生生 阅读(3843) 评论(0)  编辑  收藏 所属分类: Mysql

    只有注册用户登录后才能发表评论。


    网站导航:
     
    森露2013新款豹纹打底衫 高领 女 长袖 修身长袖t恤女 加绒加厚冬 2013春秋新款女装 潮修身大码长袖小西装外套女 韩版中长款小西装 忧忧鱼2013秋冬新款直筒裤女显瘦长裤加绒黑色休闲裤修身西裤女裤