SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to select last few records
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 08/18/2005 :  07:57:36  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
Mack writes "I want to select last 2 records from a table AA which has following 5 records.

111
222
333
444
555

There is no primary key.
Any tip will be really appretiated.
Thanks for taking time to read it."

Kristen
Test

United Kingdom
22403 Posts

Posted - 08/18/2005 :  08:00:09  Show Profile  Reply with Quote
Hi Mack, Welcome to SQL Team!

You will have to declare some sort of ORDER BY to get the "last two" - SQL has no concept of an order to the data - so if you need the last two in order or data entry you will need a "Create Date" column in the record.

SELECT TOP 2 *
FROM MyTable
ORDER BY MyColumn

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22713 Posts

Posted - 08/18/2005 :  08:11:13  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
You need to define last two

SELECT TOP 2 *
FROM MyTable
ORDER BY MyColumn DESC

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000