Как обновить последнюю mid в таблице nm на основе последней даты, присутствующей для этой mid в таблице mbr.
mbr table eid date mid 1 13/01/2019 15 for eid 1,14 is mid for latest date 1 16/02/2019 14 2 22/06/2019 18 for eid 2,18 is mid for latest date 2 25/01/2018 17 3 19/05/2019 19 for eid 3,20 is mid for latest date 3 22/08/2019 20 4 22/09/2019 44 for eid 4,44 is mid for latest date 4 25/12/2018 49 6 19/05/2019 55 for eid 6,94 is mid for latest date 6 22/08/2019 94 nm table mid nmid 15 100 14 104 18 109 17 108 19 999 20 110 44 222 49 598 55 335 94 195 expected output nm table select * from nm where mid in(select mid from mbr where eid in(1,2,4)) mid nmid 14 100 14 104 18 109 18 108 44 222 44 598 for eid 1,mid 14 is latest when compared to 15 so it should update 15 to 14 in nm table for eid 2,mid 18 is latest when compared to 17 so it should update 17 to 18 in nm table for eid 4,mid 44 is latest when compared to 49 so it should update 49 to 44 in nm table ***The query should update nm table for only specific eid's in mbr table(in our example it should update nm table only for mid's with eid=1,2,4 in mbr table and remaining mid should be unchanged in nm table) and get output in nm table.
Что я уже пробовал:
i tried with logic of selecting max date from mbr table and mid for that date and update that mid in nm table.but it is updating with same mid for all. can you please help on this. please let me know if any information needed