Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting most recent orders?
Message
From
21/08/2007 15:41:15
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Getting most recent orders?
Miscellaneous
Thread ID:
01249462
Message ID:
01249462
Views:
66
I'm trying to generate a list of Customers with their most recent Orders.
Getting the most recent Order is a simple MAX(orderdate), but how do I get the details of that one Order?

Right now it's working with a three step process, but there MUST be an easier way that I'm not seeing.
SELECT CustomerID, MAX(OrderDate) as OrderDate FROM Orders GROUP BY 1 INTO CURSOR LastOrder

SELECT Orders.CustomerID, LastOrder.OrderID, LastOrder.OrderDate, Orders.Destination, Orders.Amount ;
FROM Orders INNER JOIN LastOrder ON Orders.OrderID = LastOrder.OrderID and Orders.OrderDate = LastOrder.OrderDate ;
INTO CURSOR MostRecent

SELECT Customer.CustomerID, Customer.CustName, MostRecent.OrderID, MostRecent.OrderDate, MostRecent.Destination ;
FROM Customer INNER JOIN MostRecent ON Customer.CustomerID = MostRecent.CustomerID
Next
Reply
Map
View

Click here to load this message in the networking platform