选择另一个表中不存在的记录

时间:2016-04-19 11:02:15

标签: oracle11g

我想获取表格中不存在的x中的所有值。

我已尝试关注返回空白的查询。

select x.num from 
(
   select '888888' as num from dual union all
   select '111111' as num from dual
) x 
left outer join TableA a on (a.number = x.num)
where a.number is null


select x.num
FROM
(
    select '888888' as num from dual union all
    select '111111' as num from dual
) x
where x.num not in
(
    select a.number from TableA a where x.num = a.number
)

表格

| TableA.number |
-------------
  111111
  333333

预期的结果是只有' 888888'在这种情况下返回。

我无法理解为什么这不起作用,哪里做错了?

1 个答案:

答案 0 :(得分:1)

试试这个

with cte as
(
   select '888888' as num from dual union all
   select '111111' as num from dual
)  
select cte.num 
from cte
left join TableA a on (a.number = cte.num)
where a.number is null