wat will be the sql query to extract only last 3 records
from table supose table hving thousands for records
Answer Posted / shubhra
This query will give last three record in the table in the
same order.
CREATE TABLE dbo.Test1 (
[ID] [int] ,
[FirstName] [varchar](25),
[LastName] [varchar](25)
) ON [PRIMARY]
INSERT INTO Test1 VALUES(1, 'Bob','Smith')
INSERT INTO Test1 VALUES(2, 'Dave','Jones')
INSERT INTO Test1 VALUES(3, 'Karen','White')
INSERT INTO Test1 VALUES(1, 'Bob','Smith')
INSERT INTO Test1 VALUES(4, 'Bobby','Smita')
select identity(int,1,1) as SlNo,* into #temp from Test1
select * from (select top 3 * from #temp order by slno
desc) a order by slno
drop table #temp
| Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
How do you migrate data from mssql server to azure?
explain what is a deadlock and what is a live lock? How will you go about resolving deadlocks? : Sql server database administration
How do you rename a table in sql server?
what are the reporting service components in SSRS?
Once setting replication, is it potential to own a publisher as sixty four bit sql server and distributor or subscribers as a thirty two bit sql server?
What are the advantages of paper records?
How do I view a trc file?
Tell me can we use custom code in ssrs?
Where is my database stored on the hard disk in ms sql server?
how can you attach more than 20 ldf files in sql server
What are the kinds of subquery?
What are the character string functions supported by sql server 2005?
What is the library index called?
What is merge replication?
what is the different types of backups available in sql server? : Sql server database administration