Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Location
    Chennai,India
    Posts
    11

    Unanswered: Retrieving top 100 records from a table

    Hai,

    Firstly, I would like to appriciate Mr.RichardCrossley for his immediate responses which helped me knowing things better.

    Now my Question is,

    How to retrieve the top 100 records in a table of sybase database?
    Dont we have any rowID,Rownum type of columns default for a table as we have in oracle?
    Or, dont we have the keyword TOP in sybase as we have in SQLSERVER?

    thanx in advance,
    Niranjan.

  2. #2
    Join Date
    Jul 2003
    Location
    London
    Posts
    26

    Re: Retrieving top 100 records from a table

    Originally posted by tataniranjan
    Hai,

    Firstly, I would like to appriciate Mr.RichardCrossley for his immediate responses which helped me knowing things better.

    Now my Question is,

    How to retrieve the top 100 records in a table of sybase database?
    Dont we have any rowID,Rownum type of columns default for a table as we have in oracle?
    Or, dont we have the keyword TOP in sybase as we have in SQLSERVER?

    thanx in advance,
    Niranjan.
    Hi Niranjan,

    Sybase does not support TOP as far as I know. You have to use the SET ROWCOUNT option before running the SELECT statment.

    i.e.

    SET ROWCOUNT 100
    SELECT * FROM <tablename>
    -- Reset so all rows are returned.
    SET ROWCOUNT 0
    go

    Regards

    Richard....

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    the following will work in any database, but may not be as efficient as proprietary methods like TOP --
    Code:
    select foo
         , bar
      from yourtable X 
     where ( select count(*) 
               from yourtable  
              where foo > X.foo ) < 100
    rudy
    http://r937.com/

Posting Permissions

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