Select a.* from a inner join (select max(id) as id,Sum(1) As Count From a Group BY id)b
on a.id=b.id where exists  (select 1 from b where id = a.id)