I am trying to select the database records portion by portion, eg. first 50, then next 50, next 50 and so on..
I know SQL Server SELECT provides TOP to pickup the specified number of records, but how do I get the 51 - 100 records? Is there an any options like (MySQL LIMIT n, m ) ?
I have tried the folowing two ways :
1) SELECT TOP 50 * FROM CUSTOMER WHERE CustomerCode NOT IN (SELECT TOP 50 CustomerCode FROM Customer)
2) SELECT TOP 50 * FROM CUSTOMER WHERE CustomerCode > (SELECT TOP 1 CustomerCode FROM Customer WHERE CustomerCode IN (SELECT TOP 50 CustomerCode FROM Customer) ORDER BY CustomerCode DESC)
3) SELECT TOP 50 * FROM CUSTOMER
The efficiency as shown on SQL Query Analyzer in relative to batch is 1) 46.24 %
2) 32.45 %
3) 21.32 %
So it seems it is really too processing consuming when I need to do extra subqueries. What can I do? What causes the inefficiency?
Oh yes.. another thing. is TOP an ANSI standard of is it a T-SQL keyword?