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

Find data associated with most recent record 1

Status
Not open for further replies.

mbrichmo

Programmer
Feb 3, 2009
5
US
I would like to know how to get the data associated with the most recent record for each value of a given field i.e.:

Orders(OrderID, OrderDate, Customer, Item)

Find the most recent order for each customer and return the item for that order.

Thanks!

 
Select orders.*
from orders
inner join (Select Customer, Max(OrderDate) MaxOrderDate
from orders
Group by Customer )MaxOrder
on maxorder.Customer=orders.Customer
and maxorderMaxOrderDate=orders.OrderDate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top