Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SELECT specified number of records
Message
From
17/11/2003 11:38:24
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00850530
Message ID:
00850667
Views:
23
Hi Brenda,

Because with SELECT TOP N .. ORDER BY ...,
if record N have duplicate records respect to the ORDER BY ... rule,
the SELECT put all the duplicate on the result cursor, then _TALLY can to be
to exceed N.

But a solution exist.
If you append ,0 [ASC | DESC] to the ORDER BY clause, it is like to ,RECNO() [ASC | DESC] and this force ( RECNO() is unique ) the max RECCOUNT of the result table to N.

This behaviour is not documented, but it is not casual because -1 or other costant
are implemented like order by 1.

Then ( DELETE REST is not necessary):
* this return only the first 100 records
SELECT TOP 100 * FROM myTable ORDER BY 0 INTO CURSOR myResult
* this return only the last 100 records
SELECT TOP 100 * FROM myTable ORDER BY 0 DESC INTO CURSOR myResult
Attention, on VFP, ORDER BY is not optimized,
then, before return 100 records,
VFP build all filtered records ( WHERE results )
and then reorder
and then return TOP records.
For big filtered tables, a low level query
SELECT ... WHERE .F. INTO CURSOR myResult READWRITE && build empty cursor
SCAN WHILE RECCOUNT('myResult')<=N
 ....
 INSERT INTO myResult ...
ENDSCAN
can to be much more faster.

FABIO
Previous
Reply
Map
View

Click here to load this message in the networking platform