t1(a, b) t2(b, c)删除t1表中所有t1.b 与 t2.b 相等的数据。delete from t1  where t1.b = (select t1.b from t1, t2 where t1.b = t2.b );Error Code: 1093. You can't specify target table 't1' for update in FROM clause
这么写子查询不对吗? 要怎么用子查询来删除呢?delete t1.* from t1, t2 where t1.b = t2.b;这是对的。数据库delete

解决方案 »

  1.   

    delete t1 from t1 inner join t2 on  t1.b = t2.b
      

  2.   

    那这个子查询为什么就不对呢?哪错了?!以前在学校的时候都没试验,全都是这么写的sql语句。。
      

  3.   

    把=换成in才行另外mysql尽量不适用in子查询 改成这样
    delete  from t1
    from t1,t2
    where t1.b=t2.b
      

  4.   

    delete from t1  where t1.b in (select t2.b from t2);
      

  5.   

    Error Code: 1093. You can't specify target table 't1' for update in FROM clause提示表明这种语法不支持。 换成如下方式。
    delete t1 from  t1, t2 where t1.b = t2.b;