user5136319
user5136319

Reputation: 23

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;

Upvotes: 2

Views: 69

Answers (1)

sgeddes
sgeddes

Reputation: 62831

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

Upvotes: 4

Related Questions