select DISTINCT t.* from (SELECT stcd,max(tm) as tm from test group by stcd) as a left join test as t on t.stcd = a.stcd and t.tm = a.tm