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
What is BCP? When does it used in sql server 2012?
What options are there to delete rows on the publisher and not on the subscriber? : sql server replication
What are indexes in sql?
Explain how many types of relationship?
Why we use trigger in sql server with example?
How to find the second highest salary of an employee?
What is a result set object returned by mssql_query()?
How to change the password of a login name in ms sql server?
What are cursors? Explain the different types of cursors Enlist a few disadvantages of cursors.
How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?
What is the syntax to execute the sys.dm_db_missing_index_details?
Explain few examples of RDBMS?
What is the purpose of the master database?
What is log in sql server?
What are the different Authentication modes in SQL Server and how can you change authentication mode?