Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is BCP? When does it used in sql server 2012?

1063


What options are there to delete rows on the publisher and not on the subscriber? : sql server replication

1216


What are indexes in sql?

1281


Explain how many types of relationship?

1030


Why we use trigger in sql server with example?

962


How to find the second highest salary of an employee?

1179


What is a result set object returned by mssql_query()?

1158


How to change the password of a login name in ms sql server?

1013


What are cursors? Explain the different types of cursors Enlist a few disadvantages of cursors.

1269


How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?

1032


What is the syntax to execute the sys.dm_db_missing_index_details?

1029


Explain few examples of RDBMS?

1041


What is the purpose of the master database?

1129


What is log in sql server?

1149


What are the different Authentication modes in SQL Server and how can you change authentication mode?

1087