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

How would I query for 5 oldest orders? 2

Status
Not open for further replies.

kellstee

Technical User
Dec 31, 2005
37
US
I know how to write a basic query to find the oldest order (based on order date). How would I write a query to find the oldest 5?
 
Sample SQL
SELECT TOP 5 ...FROM yourtablename ORDER BY orderdatefield DESC

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Actually, oldest should be:
ORDER BY OrderDateField
and most recent should be:
ORDER BY OrderDateField DESC

This may return more than 5 if there are duplicate order dates. You would need to add another field to the ORDER BY clause.


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Ha.. my reading mistake..

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
The question caught me at first since you would think if the OP knew how to get the single oldest, they would know how to get the 5 oldest.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
I've just never used a "top 5" statement before. I didn't know it existed.

Thanks guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top