Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving last 20 rows

Status
Not open for further replies.

clintonwhite

IS-IT--Management
Aug 8, 2002
42
0
0
GB
Hi There,

I have tried loking through the documentation for this one, but can not seem to find anything.

I have a table that contains hundreds of rows for different machines and I want to be able to select at most 20 rows out of the table, based upon the id of the required machine. I would like to retrieve the most recent 20 rows if possible, as there is a date column in the table - however I can not seem to do this, unless I retrieve all of the rows from the table for the required machine id, sorted by ascending date and them go last and count back for 20 rows.

Is anyone aware of any condition that I can use on the select statement to achieve the same result.

Thanks for you help.
 
Try the following:

Select Top 20 *
from machineinfo
order by Datefield

John

 
I think this will give you the specific machine ID TOP 20:

Select Top 20 machineinfo.*
from machineinfo
where machineinfo.machineid = [Enter machine ID: ]
order by Datefield;

Post back with questions and more info if this is not what you wanted.


Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Thats great - exactly what I want - thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top