How to get last record for each product

2010-07-20 Thread Tompkins Neil
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

RE: How to get last record for each product

2010-07-20 Thread Jay Blanchard
[snip] 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 ? [/snip] MAX(OrderDate) -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To

Re: How to get last record for each product

2010-07-20 Thread Aveek Misra
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