Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting most recent orders?
Message
 
 
À
11/09/2008 15:36:53
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01249462
Message ID:
01346823
Vues:
7
>
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform