I have a table that looks like this:
CustomerID ProductOrdered OrderDate OrderQuantity
0001 ProdA 1/1/2007 3
0001 ProdA 1/1/2008 2
0002 ProdB 1/1/2006 1
I'm only interested the LATEST order of each customer. I'm trying to use SELECT TOP, but somehow it doesn't work with Group function:
Please advise
Thanks in advance
CustomerID ProductOrdered OrderDate OrderQuantity
0001 ProdA 1/1/2007 3
0001 ProdA 1/1/2008 2
0002 ProdB 1/1/2006 1
I'm only interested the LATEST order of each customer. I'm trying to use SELECT TOP, but somehow it doesn't work with Group function:
Code:
SELECT TOP 1 CustomerID,ProductOrdered,OrderQuantity, MAX(OrderDate) from CustomerTable group by CustomerID,ProductOrdered,OrderQuantity
Thanks in advance
Comment