delete from rt where id in
(select id 
from rt t 
where exists (
    select 1 
    from rt 
    where     typeId=t.typeId 
    and Name=t.Name 
    and nId=t.nId 
    and id<t.id
))
这条语句编译不能通过 提示错误如下:1093-you can't specify target table 'rt' for update in From clause
什么原因 如何修改?

解决方案 »

  1.   

    这个没办法,是MYSQL的限制。不能在 where 中再出现 delete from 的表一般是改成 , 但你的表估计不行,数据太多, 速度上跟不上。delete a from rt a, (
    select id 
    from rt t 
    where exists (
      select 1 
      from rt 
      where   typeId=t.typeId 
      and Name=t.Name 
      and nId=t.nId 
      and id <t.id
    )
    ) b
    where a.id=b.id
      

  2.   

    MYSQL的限制,在DELETE中用INNER JOIN