-- get lastest record of every instance SELECT * FROM [HISTORY] H WHERE [CREATEDTIME] = ( SELECT MAX([CREATEDTIME]) FROM [HISTORY] M WHERE M.[PROCESSINSTANCEID] = H.[PROCESSINSTANCEID] AND M.[EVENTTYPE] = H.[EVENTTYPE] ) ORDER BY [PROCESSINSTANCEID]
-- get lastest record of every instance SELECT * FROM [HISTORY] H WHERE [CREATEDTIME] = ( SELECT MAX([CREATEDTIME]) FROM [HISTORY] M WHERE M.[PROCESSINSTANCEID] = H.[PROCESSINSTANCEID] AND M.[EVENTTYPE] = H.[EVENTTYPE] ) ORDER BY [PROCESSINSTANCEID]