Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting most recent orders?
Message
 
 
To
11/09/2008 15:36:53
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01249462
Message ID:
01346823
Views:
6
>
>>SELECT Customer.CustomerID, Customer.CustName, Orders.OrderID, ;
>>		Orders.OrderDate, Orders.Destination ;
>>	FROM Customer ;
>>		INNER JOIN orders ON Orders.CustomerID = Customer.CustomerID ;
>>	AND OrderDate = ( SELECT MAX(OrderDate) FROM Orders Recent WHERE Recent.CustomerID = Orders.CustomerID)
>This gives me a different error - "SQL: Subquery nesting is too deep." Error 1842. Is this something that was improved with VFP 9?
>
>>
>>SELECT Customer.CustomerID, Customer.CustName, Orders.OrderID, ;
>>		Orders.OrderDate, Orders.Destination ;
>>	FROM Customer ;
>>		INNER JOIN orders ON Orders.CustomerID = Customer.CustomerID ;
>>	WHERE OrderDate = ( SELECT MAX(OrderDate) FROM Orders Recent WHERE Recent.CustomerID = Orders.CustomerID) 
>>UNION
>>SELECT Customer.CustomerID, Customer.CustName, Orders.OrderID, ;
>>		Orders.OrderDate, Orders.Destination ;
>>	FROM Customer ;
>>		LEFT JOIN orders ON Orders.CustomerID = Customer.CustomerID  where orders.OrderID IS NULL
>
>This works, but will be annoying to maintain - I may have to go back to the three step process to keep my sanity.

I don't see why UNION version is hard to maintain. IMO it quite clearly indicates the intent of the query - get most recent orders + customers without orders.

In VFP9 you can get it using derived tables. Review the whole thread, I posted alternative solution.
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