create table #t(i tinyint identity, j char(1), d datetime)
go
insert #t values('a', '1/1/99')
insert #t values('a', '1/2/99')
insert #t values('a', '1/22/99')


insert #t values('b', '2/1/99')
insert #t values('b', '1/22/99')
insert #t values('b', '4/7/99')
insert #t values('b', '5/8/99')
go
select * from #t t1
where t1.i in (select top 2 t2.i from #t t2 where t2.j = t1.j order by d desc)
This page was last updated on May 01, 2006 04:28 PM.