Results 1 to 2 of 2

Thread: TOP keyword

  1. #1
    Join Date
    Jun 2003
    Posts
    6

    Unanswered: TOP keyword

    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?

    Thanks

    rignhom

  2. #2
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    How about the indexes?
    Check the process using PROFILER for the activity.
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •