update c_visitor set pv_num=pv_num+1 
where id=(select max(id)
 from c_visitor 
 where c_info_id =1 
 and curUrl='http://127.0.0.1:8081/hboys');
我想更新c_visitor,根据 c_info_id =1 and curUrl='http://127.0.0.1:8081/hboys' 的条件,可是报错
you can't specify target table 'c_visitor; for update in from clause如果我单独执行,是可以的
但是我想合并到一起
不知道怎么办
请各位高手指点

解决方案 »

  1.   

    update c_visitor set pv_num=pv_num+1 
    where id=(select max(id)
     from c_visitor 
     where c_info_id =1 
     and curUrl='http://127.0.0.1:8081/hboys');----------------------------------------------语法没有问题。
      

  2.   

    Sorry!看错了,以为是SQL Server 帖子.
      

  3.   

    sql执行错误 # 1093 从数据库的响应:
    you can't specify target table 'c_visitor; for update in from clause
      

  4.   

    可能是这样的:
    当在进行更新的时候,表就被锁定这时是不允许进读取操作的.而你在子查询与更新表使用的是同一个表,所以出了问题.所以只能分开写了,max(id)存在一个变量里,然后再进行更新,或者想其它的办法
      

  5.   

    UPDATE pw_members SET email='[email protected]' WHERE uid=(select uid from pw_members where username='xsx')
    郁闷,那位仁兄给予指点!!!!