Hello experts below is my code: I have different tables where I have the data. One material MYCODE is compound of different raw materials like 01-, 04- and 05-. For each of them I should find out the last date (max date of purchase) which is max(tp_date). below is my code: but the output is showing 2 different dates for the first material 01-. I need just the last one, so the line with the order date 2015-04-22 please help:
select dmprod.pr_codenum pr_co, dmprod.pr_descrip desc,
max(dttpur.tp_date) Date, dmfcur.fc_name CURR,
(select pr_codenum from
dmprod where dmprod.pr_id=dmbom.bo_bomfor)BOM,
max(dmrev.re_name) Rev,
sum(dmbom.bo_quant)*dtpur.pu_price Ext,
dmunit.un_name mea,
dtpur.pu_price price from dmbom, dmprod,
dmrev, dmunit, dttpur, dmfcur, dtpur
where dmbom.bo_prid=dmprod.pr_id
and dttpur.tp_fcid=dmfcur.fc_id
and dmprod.pr_id=dtpur.pu_prid and dttpur.tp_id=dtpur.pu_tpid
and dmbom.bo_unid=dmunit.un_id
and dmrev.re_id=dmbom.bo_reid
and pr_active=1 and (select pr_codenum from dmprod where dmprod.pr_id=dmbom.bo_bomfor)='MYCODE'
group by pr_codenum, pr_descrip, fc_name,un_name,
pu_price, bo_bomfor
and the output is:
pr_co des Date CURR BOM Rev Ext mea price
01- T 2015-04-22 USD MYCODE 01 127 mg 2
01- T 2015-02-26 USD MYCODE 01 290 mg 4
04- M 2016-01-12 EUR MYCODE 01 300 mg 7
05- S 2016-02-25 EUR MYCODE 01 260 mg 4