>>HistoryId PartId SerialNo ActionDate Sequence >>---------------------------------------------------------------------------------------------- >>2920 2 Serial 1 2009-05-11 14:46:09.407 1 >>2923 2 Serial 1 2009-05-11 14:47:05.767 2 >>2921 3 Serial 2 2009-05-11 14:46:09.420 1 >>2924 3 Serial 2 2009-05-11 14:47:05.860 2 >>2927 3 Serial 2 2009-05-11 14:46:09.000 3 >>2922 4 Serial 3 2009-05-11 14:46:09.447 1 >>>>
>> >>SELECT * >> FROM LocationHistory lh1 >> WHERE ActionDate = >> (SELECT MAX(ActionDate) >> FROM LocationHistory lh1 >> WHERE lh1.HistoryId = lh1.HistoryId) >>>>
>select LH.* from LocationHistory LH inner join (select Max(ActionDate) as MaxDate, > PartID, SerialNo from LocationHistory group by PartID, SerialNo ) Derived on > LH.PartID = Derived.PartID and LH.SerilNo = Derived.SerialNo and LH.ActionDate = Derived.MaxDate >>
>>SELECT * >> FROM LocationHistory lh1 >> WHERE SerialNo = >> (SELECT MAX(SerialNo) >> FROM LocationHistory lh1 >> WHERE lh1.HistoryId = lh1.HistoryId) >>>>I got back only row 2922.