delete from A a where a.id in (select b.id from B b)顺便问一句:还有别的方法实现关联删除吗?

解决方案 »

  1.   

    delete from A a where  exists (select 1 from from B b where a.id = b.id )
      

  2.   

    delete from A a where exists (select 1 from B b where a.id = b.id )
      

  3.   

    你这个已经很不错了。
    用exists比用in或not in好不到哪里去。
      

  4.   

    一般情况下是exits>in>not in.
    如果数据量很小的话,之间的差别可以忽略不计
      

  5.   


    对于外表数据比嵌套的数据少 就exists  相反则in 
      

  6.   

    用in时内表需要排序,外表大内表小的时候用in
    用exists时,内表可以使用缩影,内表大的时候使用exists效果好点
      

  7.   

    至于exists和in的区别,8楼说的比较详细。另外,级联删除你可以试试查看用cascade