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

Max query function

Status
Not open for further replies.
Aug 24, 2005
56
US
Hello,

I am working with a purchase order table that has a field called [CreateDate]. Each [ItemNumber] might have multiple purchase orders with a different [CreateDate].

How can I run query to only show the records for the last created puchase order for each item?

Thanks,

cordeiro82
 
I wanted to add some more information

There are five fields in the table [ItemNumber], [CreateDate], [PONumber], [OpenQty], [Supplier]

In addition to finding the last purchase order created (Max[CreateDate]) for each item is it possible to only return the largest qty if there are more than two Purchase orders for any given item on the same date?
 
Are you suggesting you don't have a single field primary key in your table? Can you add one? If so,
Code:
SELECT *
FROM tblNoNameProvided
WHERE ID = (SELECT TOP 1 ID FROM tblNoNameProvided N WHERE N.ItemNumber= tblNoNameProvided.ItemNumber ORDER BY CreateDate Desc, OpenQty Desc, ID Desc)

Duane MS Access MVP
Now help me support United Cerebral Palsy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top