Get Recent records from the table

Here is a small code snippet for getting the recent records from the table. 

drop table VENKAT_TABLE
go
create table Venkat_Table(code varchar(100),rate decimal(10,8),date1 date)
go
insert into VENKAT_TABLE values ('sam', 1.240000, '01/08/2004') 
insert into VENKAT_TABLE values ('sam', 1.840000, '02/08/2004') 
insert into VENKAT_TABLE values ('pal', 1.240000, '01/08/2005') 
insert into VENKAT_TABLE values ('pal', 0.840000, '10/08/2003') 

select code,rate,date1 from 
(
select ROW_NUMBER() over (partition by code order by date1) as rank1,*
  from VENKAT_TABLE ) t
  where rank1=1
 
Cheers,
Venkatesan Prabu .J
Head, KaaShiv InfoTech
Ebook Download
View all
Learn
View all