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
Should you normalize audio?
What number sorts of privileges are accessible in sql?
How to create a user name in a database?
What is the difference between row_number and dense_rank?
How to modify an existing user defined function?
How display code or Text of Stored Procedure using Sql query in Sql Server ?
Can multiple columns be used in sql group by clause in ms sql server?
What is equi join with example?
Are null values the same as that of zero or a blank space?
How to change a login name in ms sql server?
What is TDS(Tabular Data Stream) Gateway?
What is difference between equi join and natural join?
What are the different methods available under sqlcommand class to access the data?
What is ssl in sql server?
What are the general features of sql server management studio? : sql server management studio