List:General Discussion« Previous MessageNext Message »
From:Aveek Misra Date:July 20 2010 12:16pm
Subject:Re: How to get last record for each product
View as plain text  
SELECT ProductID, MAX(OrderDate) FROM table GROUP BY ProductID;

or if you want all the columns

SELECT * FROM table a, (SELECT ProductID, MAX(OrderDate) as MaxDate FROM 
table GROUP BY ProductID) as b WHERE a.ProductID = b.ProductID AND 
a.OrderDate = b.MaxDate;

Tompkins Neil wrote:
> Hi,
>
> I have a list of product orders in a table with the following structure :
>
> OrderID
> ProductID
> OrderDate
> OrderCost
>
> What query would I need to get the last order for each productID ?
>
> Cheers,
> Neil
>   

Thread
How to get last record for each productTompkins Neil20 Jul
  • RE: How to get last record for each productJay Blanchard20 Jul
  • Re: How to get last record for each productAveek Misra20 Jul