select a.* from testTable a inner join (select id,MAX(InDate) as InDate from testTable group by id) b on a.id=b.id and a.InDate =b.InDate