Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL-Cmd Select Top slows down query, why?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
SQL-Cmd Select Top slows down query, why?
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
00953905
Message ID:
00953905
Views:
50
Hi all,

I have a large table in the following format:
Table name: table1
Record count: 137,866
Fields: filenum I,field1,field2...field124
index: filenum 
I've created a query form allowwing the user to select top N of records in the following manner:
select top nSelectCount ;
     * ;
   from table1 ;
   where filenum >= nFilenum ;
   order by filenum ;
   into cursor curMySelection ;
   nofilter 
The user determines the values of nSelectCount and nFilenum through the form interface.
But the above query runs so much slower compared to the following query statement:
select top nSelectCount ;
     * ;
   from table1 ;
   where filenum >= nFilenum and filenum <= nFilenum + nSelectCount;
   order by filenum ;
   into cursor curMySelection ;
   nofilter 
The reason I couldn't use the second statement is that the filenum is not always in sequence due records deletion, therefore the user doesn't get top nSelectCount, worse yet sometimes he gets nothing.

Is there a way to speed up query with TOP option included the first statement?

TIA
Dawa Tsering


"Do not let any unwholesome talk come out of your mouths,
but only what is helpful for building others up according to their needs,
that it may benefit those who listen."

- Ephesians 4:29-30 NIV

Dare to Question -- Care to Answer

Time is like water in a sponge, as long as you are willing you can always squeeze some.

--Lu Xun, Father of Modern Chinese Literature

Next
Reply
Map
View

Click here to load this message in the networking platform