|
-
Sep 4th, 2003, 05:39 AM
#1
Thread Starter
Lively Member
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
-
Sep 4th, 2003, 08:43 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|