select * from Table1 where
ID in(select max(ID) from Table group by Flag)