select id, parent_id from jj_sort where id not in ( select parent_id from jj_sort ) and channel=2;
这样可正常显示数据出来update jj_sort set groups='0' where id not in ( select parent_id from jj_sort ) and channel=2;
这样却提示错误如下:
错误代码: 1093
You can't specify target table 'jj_sort' for update in FROM clause
(耗费 0 ms)请问怎么解决?

解决方案 »

  1.   

    mysql的update命令中的select子句不能是被update的表。
      

  2.   

    You   can't   specify   target   table   'jj_sort'   for   update   in   FROM   clause 错误提示就可以明白了~
      

  3.   

    where   id   not   in   ( select * from (select parent_id  from jj_sort) as tmptbl )
    and   channel=2; 
      

  4.   


    create temporary table tmp  select   parent_id   from   jj_sort;
    update   jj_sort a,tmp b set a.groups='0' where   a.channel=2 and a.id != b.parent_id;