How to get last record for each product

--0016e68de9e0d6e491048bd01ff6
Content-Type: text/plain; charset=ISO-8859-1

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

--0016e68de9e0d6e491048bd01ff6--
Tompkins Neil [ Di, 20 Juli 2010 13:38 ] [ ID #2044795 ]

RE: How to get last record for each product

[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 unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2 [at] m.gmane.o rg
Jay Blanchard [ Di, 20 Juli 2010 13:51 ] [ ID #2044796 ]

Re: How to get last record for each product

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
>


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2 [at] m.gmane.org
Aveek Misra [ Di, 20 Juli 2010 14:16 ] [ ID #2044797 ]
Datenbanken » gmane.comp.db.mysql.general » How to get last record for each product

Vorheriges Thema: mysql-workbench-gpl-5.2.25-1el6.x86_64.rpm depends on a lot of stuff I donot have
Nächstes Thema: Select ROW_COUNT() INTO a variable