51Testing软件测试论坛

标题: 关于数据库的题目,求解 [打印本页]

作者: liuyuanyuan133    时间: 2013-7-24 19:18
标题: 关于数据库的题目,求解
A,B 两个数据库表都是百万记录,A表的aid与B表的bid关联,但B表中有部分bid 在A表中没有对应的aid
,要求删除B表中这些没有对应的记录。
作者: 洞箫    时间: 2013-7-25 14:35
delete from B where bid not in (select aid from A)
作者: wuxi88    时间: 2013-7-25 17:00
delete from B where bid not in (select aid from A);  --若B表相对更大一点
delete from B where not exists(select A.aid from A where A.aid=B.bid);  --若A表相对更大一点




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2