Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting most recent orders?
Message
 
 
To
21/08/2007 15:41:15
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01249462
Message ID:
01249464
Views:
15
Chris,

Please see Re: MAX function Thread #1247432 Message #1247435

>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
>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform