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

Is it safe to delete log files?

971


Is BCNF better than 2NF & 3NF? Why?

1104


Why Master database is required?

1185


What is clustered vs nonclustered index?

1001


What is role playing dimension with two examples? : sql server analysis services, ssas

1052


How to get the definition of a trigger back?

1045


How to find table changes in sql server?

1173


what is the maximum size of a row? : Sql server database administration

1080


Explain the properties of sub-query in sql server?

1069


How to turn off warning messages during php execution?

1106


How to return the second 5 rows in ms sql server?

1106


Write a SQL queries on Self Join and Inner Join.

1077


What are different types of raid levels?

1235


How to write a query with a full outer join in ms sql server?

1156


How to create a simple table to test triggers in ms sql server?

1034