Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SELECT TOP ???
Message
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
SELECT TOP ???
Miscellaneous
Thread ID:
00396652
Message ID:
00396652
Views:
24
SELECT TOP1 * FROM B_PODS INTO CURSOR csrRETURN ORDER BY DESCRIP

You'd expect it to return 1 row right? The help file below seems to say that...

Selecting a Number or Percentage of Records
If you only need a certain number or percentage of records from the result set that your query would return, you can use the Top property on the Miscellaneous tab in the Query or View Designers or you can add a TOP clause to your SELECT - SQL statement. The number you provide in a TOP clause can range from 1 to 32,767. For a percentage, you can use from 0.001 to 99.99.
For example, if you want to select the top 10 customers with the highest order amounts, you can specify a GROUP BY on CUST_ID to show one aggregate record for each customer and sort by ORDER_AMT in the ORDER BY clause. To get a true TOP 10, you need to specify a descending sort on the ORDER_AMT so that the records with the highest order amounts appear first in the results. If you use an ascending sort, the result records are ordered from the least order amount to the most. The top records you select from the result set would actually have the lowest values.

BUT NO! If the descrip field is blank in 8 records, they sort to the top and you get all 8 blanks. One value (blank), but 8 records.

Does this seem right to anyone?


I've never used the TOP clause before, because I know it creates the entire recordset first, then chops off the top X and can be as slow as returning the entire set. In this case, I'm converting the records to XML and returning them to a client from a COM component, so I really do need to limit the number of rows to X. Do I need to COPY NEXT x. In a separate step to make this work?
Next
Reply
Map
View

Click here to load this message in the networking platform