在Oracle中加入两个表

时间:2015-09-20 05:09:36

标签: sql oracle

enter image description here

我需要类似的东西:

select * 
from table1 
where {if PKID = MasterPKID - (that PKID should not be present as refNo in table2)}.

ie-652不应出现在表2中

我完全无能为力。

我们可以在一个查询中实现吗?

1 个答案:

答案 0 :(得分:2)

使用Not exists

select * 
from table1 a
where PKID = MasterPKID
and not exists (select 1 from table2 b where a.PKID = b.refno)