原帖由 junsansi 于 2008-9-24 15:14 发表
select * from b where targetid not in(select id from a)
三思给的语句可读性好,不过如果表大的话性能会很差,
2楼给的应该是最快的,
补充一种(效率仅次于2楼的):
select * from b where not exists (select 'x' from a where a.targetid= b.id )
[ 本帖最后由 zouhu007 于 2008-9-24 19:40 编辑 ]
三思给的语句可读性好,不过如果表大的话性能会很差,
2楼给的应该是最快的,
补充一种(效率仅次于2楼的):
select * from b where not exists (select 'x' from a where a.targetid= b.id )
三思兄的写法不一定效率差,要看情况,in是基于外部表驱动的,exists是基于内部表驱动的,要看是内表大还是外表大!