Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Last 3 orders from each customer - sql puzzle
Message
From
25/09/1999 14:09:06
Cindy Winegarden
Duke University Medical Center
Durham, North Carolina, United States
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00268263
Message ID:
00268973
Views:
35
>Actually, I glad you replied because now I don't have to go searching for this thread. I guess I was brain dead the other day and missed the obvious answer.
>
>SELECT *
>FROM orders INNER JOIN ordlines
> orders.orderid = ordlines.orderid
>WHERE orders.orderid IN (
> SELECT TOP 3 orderid
> FROM orders
> ORDER BY orderdate DESC)
>
>-Mike

Mike,

The followint (Use the VFP sample data) doesn't work:

SELECT orders.*, orditems.* ;
FROM orders INNER JOIN orditems ON orders.order_id = orditems.order_id ;
WHERE orditems.lineno IN ;
(SELECT TOP 3 lineno FROM orditems ORDER BY quantity DESC)

This is exactly why the question was originally posted, you can't put a SELECT TOP x in a subquery. I wrestled with this last winter, and settled on the loop-and-accumulate solution to get the top x in each of my categories.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform