Oracle表查询问题
test1表:
name字段值:zhangsan,lisi,wangwu;
test2表:
name字段值:zhangsan,wangwu,zhaoliu;
现在的问题是我要获得test1表中在test2表中不存在的name值(也就是lisi)。
除了用not in以外(数据量比较大性能不怎么好)。
还可以怎么写???
[最优解释]
select name from test1
minus
select name from test2
[其他解释]
with t1 as
(
select 'zhangsan' c1 from dual
union all
select 'lisi' c1 from dual
union all
select 'wangwu' c1 from dual
union all
select 'houliu' c1 from dual
),t2 as
(
select 'zhangsan' c2 from dual
union all
select 'wangwu' c2 from dual
union all
select 'zhaoliu' c2 from dual
)
select c1
from
(
select c1,c2
from t1 left join t2 on c1 = c2
)
where c2 is null
c1
----------------------
1houliu
2lisi