select * from a where not exists (select f1 from b where a.f1 = b.f1)
写个难点的,在执行效率上不知哪一个更好select a.* from a inner join b on a.fl<>b.f1
select a.* from a where not exists (select b.f1 from b where a.f1=b.f1)
select * from a where f1 not in (select f1 from b)
如果在a,b中f1不是唯一主键的话不能用select a.* from a inner join b on a.fl<>b.f1,如果f1允许为空的话不能select * from a where f1 not in (select f1 from b)语名,这样如果a中f1为空是将得不到你想要的结果,此时可以改用select * from a where f1 not in (select f1 from b) or f1 is null
select * from a where f1 not in (select f1 from b) 或 select * from a where not exist (select * from b where b.f1=a.fi) 前提是f1是两表中的唯一关键字,却不为null:
so easy :)
so easy :)
where not exists (select b.f1 from b where a.f1=b.f1)
select * from a where not exist (select * from b where b.f1=a.fi)
前提是f1是两表中的唯一关键字,却不为null: