I'm having select script inside left outer join witch I'm using for getting values
SELECT discount, osp_id, sero_id, estpt_id, max(festpae_id) festpae_id FROM database1 data1 JOIN database2 data2 ON data2.id = data1.attr_id WHERE data1.interest_rate = 1 AND data1.ordet_id = data2.id AND data1.objt_attr_id = data2.objt_attr_id GROUP BY osp_id, sero_id, estpt_id; From this select i'm getting this output
DISCOUNT OSP_ID SERO_ID ESTPT_ID FESTPAE_ID ---------- ---------- ---------- ---------- ---------- 50 619356 3931831 2144 2000743 40 619356 3931831 2144 2000744 This is not correct for me, because i need to get only 1 output, which means I'm looking for highest FESTPAE_ID, so the correct output of the script should be this
DISCOUNT OSP_ID SERO_ID ESTPT_ID FESTPAE_ID ---------- ---------- ---------- ---------- ---------- 40 619356 3931831 2144 2000744 I know, that if I will use MAX() on dicount row, then he will return me only 1 record with FESTPAE_ID = 2000743, which is not my goal.
What do I need to adjust to make it work as i want? So he would return only 1 record based on higest FESTPAE_ID and do not care other values like discount.
P.S This script is used in view table as LEFT OUTER JOIN, so if i order it by festpae_id and then set rownum = 1 it doesn't work properly in view table(but it works if run separately from whole view table select(as left outer join)), that's why i'm asking your help how to do it with MAX(). Or there is any better way?