Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2006
    Posts
    12

    Unanswered: SQL query to return last x rows

    Hi

    I have a list of results from an sql query which I would like to return the last 5 rows only. Is there a function in sybase to do so?

    Thanks!

  2. #2
    Join Date
    Jan 2003
    Location
    Geneva, Switzerland
    Posts
    353
    Reverse the order by, and fetch the first 5 rows, using either "set rowcount 5" or if you are using 12.5.2 or later SELECT TOP 5 ...

    Michael

  3. #3
    Join Date
    Dec 2006
    Posts
    7
    Found a bug related to "select top n" query. it is not working with union all option. please correct me, If I miss anything.


    select top 2 * from
    (select a=8
    union all
    select a=9
    union all
    select a=8
    union all
    select 10
    ) as derv

  4. #4
    Join Date
    Jun 2005
    Location
    Singapore
    Posts
    60
    select top 2 * from
    (select a=8
    union all
    select a=9
    union all
    select a=8
    union all
    select 10
    ) as derv order by 1

Posting Permissions

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