General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
>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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only