从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')
请指教。谢谢。
想这样写,但好象不行。SQL的嵌套写法不是很熟。
delete from db_b where b_id=(select a_id from db_a where fld_c='x')
请指教。谢谢。
to Delphityro(delphi民工),兄弟啊我也来晚了,我的MSN:[email protected],联系我哦
delete from db_b where b_id in (select a_id from db_a where fld_c='x')
可以
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)
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)