As you see below; how can I implement fx.ftf_validitystartdate= … this lines value since oracle does not allow me to do it like this below
.
select * from acc_accounts acc
join kp_paramcore p on
acc.account_no = p.accountnum
acc.suffix = p.suffixc
LEFT JOIN ftf_rates fx
ON p.maturestart = fx.ftf_vadealtsinir
AND p.maturefinish = fx.ftf_vadeustsinir
AND fx.statusrec = 'A'
AND fx.currencycode = acc.currencsw_kod
AND fx.status= 'A'
and fx.ftf_validitystartdate= (SELECT MAX(ff.ftf_validitystartdate)
FROM ftf_rates ff
WHERE ff.status = 'A'
AND ff.statusrec = 'A'
AND v_CurrentDate BETWEEN ff.systemstartdate AND ff.systemfinishdate AND ff.currencycode = acc.currencsw_kod
)
I publish the workaround with CTE and tested only in Oracle 11g.
To make test I create this schema:
At this time I force error with this query:
And now I rewrite query with CTE:
This second query returns right results.
I rewrite your query with CTE:
Notice, only tested in Oracle 11g. See @a_horse_with_no_name coment: