从A表中SELECT符合条件的记录集,根据该记录集来删除B表对应的记录(a_id和b_id一一对应),
想这样写,但好象不行。SQL的嵌套写法不是很熟。
delete from db_b where b_id=(select a_id from db_a where fld_c='x')
请指教。谢谢。

解决方案 »

  1.   

    这样我当然会阿。就是想一个SQL语句。
      

  2.   

    select a_id from db_a where fld_c='x';s:=fieldByName('a_id').asstring;//s为查询的中间变量delete from db_b where b_id=s;试试吧。应该行的。
      

  3.   

    delete from db_b where b_id in (select a_id from db_a where fld_c='x')
      

  4.   

    delete from db_b where b_id in (select a_id from db_a where fld_c='x');用in(包含于)
      

  5.   


    to  Delphityro(delphi民工),兄弟啊我也来晚了,我的MSN:[email protected],联系我哦  
      

  6.   

    试试
    delete from db_b where b_id in (select a_id from db_a where fld_c='x')
      

  7.   

    delete from [table1] where column in (select [column] from [table1] where .....)用in啊~!
      

  8.   

    delete from db_b where b_id in (select a_id from db_a where fld_c='x')
    可以
      

  9.   

    当两个表的数据量较大时(至少百万计),语句
    delete from db_b where b_id in (select a_id from db_a where fld_c='x')
    效率太低。
    不妨执行下面语句 
    (Oracle适用)
    delete from db_b B
     where Exists (select * from db_a 
                     where fld_c='x'
                       And B.b_id=a_id)
    (SQL Server适用)
    delete B
     from db_b B
     where Exists (select * from db_a 
                     where fld_c='x'
                       And B.b_id=a_id)
      

  10.   

    这样效率会更高吗?(SQL Server适用)
    delete B
     from db_b B
     where Exists (select top 1 a_id from db_a 
                     where fld_c='x'
                       And B.b_id=a_id)
      

  11.   

    delete from db_b where b_id in (select a_id from db_a where fld_c='x')