Thursday, October 7, 2010

Display Last 3 Records in Table

--Display Last 3 Records in Table

create table #table
(
no int identity (1,1),
name varchar(20),
addr varchar(100)
)

insert into #table values ('ABC','Pune')
insert into #table values ('XYZ','mumbai')
insert into #table values ('KLM','Satara')
insert into #table values ('OPQR','Hyderabad')
insert into #table values ('JKLM','Sholapur')
insert into #table values ('GHIJ','Pune')
insert into #table values ('RETU','Bombai')

select * from #table

select top 3 * from #table order by no desc

--OUTPUT IS
--
--7 RETU Bombai
--6 GHIJ Pune
--5 JKLM Sholapur

No comments: