Results 1 to 4 of 4

Thread: sql query help

  1. #1
    Join Date
    Dec 2001
    Posts
    2

    Exclamation Unanswered: sql query help

    Hi friends
    Can any one of you let me know how to select records from record number x to xx in sql 2000
    thanks in advance

  2. #2
    Join Date
    Dec 2001
    Location
    Toronto, Canada
    Posts
    335
    Use the TOP statement in your SELECT. First you must decide on what determines the order of a record, "What makes a record 15th out of 50?". I my example (I'll use the PUBS database and the AUTHORS table) the AU_ID determines a records rank or order. So lets say I want records 15 throught 20, I would write:

    select top 5 *
    from (
    select top 20 *
    from authors
    order by
    au_id
    ) x
    order by
    au_id desc

    I use AU_ID to set my order, get my 20 records first then count back to the 15th record from there which is 20-15 = 5. Note you can also add in the keywords "WITH TIES", see Books Online from more info.

  3. #3
    Join Date
    Sep 2003
    Location
    Memphis
    Posts
    62
    If there is an id, couldn't you just say WHERE Au_ID BETWEEN X AND XX ?

  4. #4
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    SELECT TOP NUMBER_OF_ROWS *
    FROM table
    WHERE key NOT IN
    (SELECT top BEGIN_AT key
    FROM table
    ORDER BY orderColumn)
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

Posting Permissions

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