R
Ramesh
Hi,
I use the following query to get the last order of each Cust ID with help
from Allen Browne's tips site. Now my requirement is slightly different in
the sense, i need to have last order for each Cust ID for each Product ID
too. If same customer has ordered 2 products, then i need to get the last
order for each of the products.
SELECT Orders.CustomerID, Orders.OrderDate, Orders.OrderID
FROM Orders
WHERE Orders.OrderID IN
(SELECT TOP 1 OrderID
FROM Orders AS Dupe
WHERE Dupe.CustomerID = Orders.CustomerID
ORDER BY Dupe.OrderDate DESC, Dupe.OrderID DESC)
ORDER BY Orders.CustomerID, Orders.OrderDate, Orders.OrderID;
Could someone help in including the Product ID too? I am not too familiar
with sql code, just beginning learn.
Thanks very much for any help.
Ramesh
I use the following query to get the last order of each Cust ID with help
from Allen Browne's tips site. Now my requirement is slightly different in
the sense, i need to have last order for each Cust ID for each Product ID
too. If same customer has ordered 2 products, then i need to get the last
order for each of the products.
SELECT Orders.CustomerID, Orders.OrderDate, Orders.OrderID
FROM Orders
WHERE Orders.OrderID IN
(SELECT TOP 1 OrderID
FROM Orders AS Dupe
WHERE Dupe.CustomerID = Orders.CustomerID
ORDER BY Dupe.OrderDate DESC, Dupe.OrderID DESC)
ORDER BY Orders.CustomerID, Orders.OrderDate, Orders.OrderID;
Could someone help in including the Product ID too? I am not too familiar
with sql code, just beginning learn.
Thanks very much for any help.
Ramesh