简体   繁体   中英

left outer join in oracle issues

In this query below, I need left outer join to work so that resulting dataset contains all the values of a.terr_num that match and unmatch with b.terr_num

somehow this is not working.. please help

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;

If I'm understanding your question correctly, you are negating your outer join with the where criteria. Move that criteria to the join instead:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM