I'm trying to join these two tables together to show the record in base and the null in history. The problem I am having is with a left outer join. when BO.val2 = 0: I want the join to use BO.VAL5 = TR.VAL5 only but when BO.val2 = TR.val2 I want it to use that for the join. The code below is a just idea. If you have any suggestion on how to do this that would be great!
SELECT DISTINCT
BO.RUN_DATE,
BO.val2,
BO.val3,
BO.val4,
BO.VAL5
TR.DTDATE,
TR.val2,
TR.val3,
TR.val4,
TR.val5
FROM BASE BO
LEFT OUTER JOIN HISTORY AS TR ON CASE
WHEN BO.val2 = 0 and BO.VAL5 = TR.VAL5 THEN ????
WHEN BO.val2 = TR.val2 and BO.VAL5 = TR.VAL5 then ???
ELSE ??
END
WHERE TRUNC(BO.POST_DATE)= TRUNC(SYSDATE)
ORDER BY BO.VAL4 ;