Results 1 to 2 of 2

Thread: Oracle Equivalent to SQL Server TOP function

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Location
    Reading
    Posts
    70

    Oracle Equivalent to SQL Server TOP function

    Does anyone know if there is an equivalent to SQL Servers top

    (select top 5 from tblAudits where somevalue is not null)

    in Oracle 9i? ?


    Many Thanks,

    AuldNick

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    You can use ROWNUM in Oracle. I just did a test and it would appear that you should apply this to a resultset that is already sorted the way you want (unless you don't care and will take ANY 5 records), as opposed to the table directly (someone may correct me on this).

    But the following will surely work (note that a table EXPRESSION is used in the FROM clause):
    SELECT T.*
    FROM (select * from tblAudits where somevalue is not null order by somefield desc) T
    WHERE ROWNUM < 6

    If you just do the following, I don't think you'll get the expected results:
    SELECT * from tblAudits
    where somevalue is not null
    and ROWNUM < 6
    order by somefield desc
    "It's cold gin time again ..."

    Check out my website here.

Posting Permissions

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



Click Here to Expand Forum to Full Width