select * from t as tmp where not exists(select 1 from t where id=tmp.id and time<tmp.time)
create table T(id varchar(10), num decimal(10, 1), [time] varchar(10)) insert T select '01', 2, '9:10' union all select '01', 1, '9:11' union all select '02', 4, '8:27' union all select '03', 1.2, '10:10' union all select '03', 11, '10:15'select * from t as tmp where not exists(select 1 from t where id=tmp.id and time<tmp.time)--result id num time ---------- ------------ ---------- 01 2.0 9:10 02 4.0 8:27 03 1.2 10:10(3 row(s) affected)
select * from t as tmp
where not exists(select 1 from t where id=tmp.id and time<tmp.time)
insert T select '01', 2, '9:10'
union all select '01', 1, '9:11'
union all select '02', 4, '8:27'
union all select '03', 1.2, '10:10'
union all select '03', 11, '10:15'select * from t as tmp
where not exists(select 1 from t where id=tmp.id and time<tmp.time)--result
id num time
---------- ------------ ----------
01 2.0 9:10
02 4.0 8:27
03 1.2 10:10(3 row(s) affected)