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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select last 5 records only

Status
Not open for further replies.

florida41

Technical User
May 13, 2004
95
US
I need to fetch just the last 5 records when I query my Access 2000 database:

Code:
select * from TableOne where project_id = 10;

If I have 10 hits on the above how can I make sure it just selects the last 5 records?
 
select top 5 * from TableOne where project_id = 10
order by yourSortField desc;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
is there some way to tell which 5 you need? The ones with the largest ID number? The latest time? What is the criteria, just being the last 5 records entered into the table?



Leslie
 
The last 5 records so it would be the largest ID numbers.
 
then change PHV's answer to

ORDER BY ID DESC

Leslie
 
select TOP 5 * from TableOne ORDER BY Project_Id DESC;

-VJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top