So I found this similar question and answer at (Find max value and show corresponding value from different field in SQL server) but I want to take it one step further. I want to get the latest date for each ID and the corresponding TYPE instead of just the absolute max for all entries. Any suggestions?
ID Type Date
1 Initial 1/5/15
1 Periodic 3/5/15
2 Initial 2/5/15
3 Initial 1/10/15
3 Periodic 3/6/15
4 Initial 3/8/15
The code below shows how to get just the max date of ALL entries, but I want the max date for each ID and then the corresponding Type.
select id, type, date
from yourtable
where date in (select max(date)
from yourtable)
OR
select id, type, date
from yourtable t1
inner join
(
select max(date) maxdate
from yourtable
) t2
on t1.date = t2.maxdate;