So, I have a list that looks something like this. Its basically a state history for a bunch of items, with the most recent state representing the current state.
Record Id State Date
===== === ========= =======
1 A Waiting Jan 01
2 A InProgress Jan 02
3 A Finished Jan 03
4 B Waiting Jan 02
5 C Waiting Jan 01
6 C InProgress Jan 02
7 D Waiting Jan 01
8 D InProgress Jan 02
What I'm looking for is to be able to query the 'current' state for each item. For example, I'd like to say: "Give me all Ids are are 'InProgress'" and get Id D and Id C, but not Id A (because its latest state is 'Finished').
I know I've got to do some grouping and some ordering or Maxing, but I can't quite put it all together.