在oracle问题中左外连接

时间:2018-12-28 20:49:16

标签: sql oracle

在下面的此查询中,我需要左外部连接才能起作用,以便所得数据集包含与b.terr_num匹配和不匹配的a.terr_num的所有值

这不起作用。.请帮助

select   b.sales_regn, b.sales_area,  b.terr_num, a.terr_num,  a.terr_name
from     kp_terr_region b
         left outer join  kap_terr  a on a.terr_num = b.terr_num
where    a.valid_to > sysdate
and      a.ptr_type = 'JPN'
and      a.status != 1
and      a.valid_to > sysdate
and      b.valid_to > sysdate
and      a.slr_num is null;

1 个答案:

答案 0 :(得分:4)

如果我正确理解了您的问题,则说明您的outer joinwhere条件相反。将该标准移到join上:

select   b.sales_regn, b.sales_area,  b.terr_num, a.terr_num,  a.terr_name
from     kp_terr_region b
     left outer join  kap_terr  a on a.terr_num = b.terr_num
         and a.valid_to > sysdate
         and a.ptr_type = 'JPN'
         and a.status != 1
         and a.slr_num is null
where b.valid_to > sysdate