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 to automatically create a log when an exception is being received into SQL Server?
How to recreate an existing index in ms sql server?
What is the stuff?
What is dml command?
What is the advantage of sql server?
Describe in brief authentication modes in sql server.
What is an indexing strategy?
what is a join? : Sql server database administration
Can an automatic recovery be initiated by a user?
What is the most common trace flags used with sql server?
What is the difference between ‘having’ clause and a ‘where’ clause?
How would we use distinct statement? What is its use?
What is user-defined scalar function?
What is sql view?
What is a raid and what are different types of raid configurations?