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
Is it safe to delete log files?
Is BCNF better than 2NF & 3NF? Why?
Why Master database is required?
What is clustered vs nonclustered index?
What is role playing dimension with two examples? : sql server analysis services, ssas
How to get the definition of a trigger back?
How to find table changes in sql server?
what is the maximum size of a row? : Sql server database administration
Explain the properties of sub-query in sql server?
How to turn off warning messages during php execution?
How to return the second 5 rows in ms sql server?
Write a SQL queries on Self Join and Inner Join.
What are different types of raid levels?
How to write a query with a full outer join in ms sql server?
How to create a simple table to test triggers in ms sql server?