Oracle equivalent of SQL Server SELECT TOP (SELECT TOP n)

I had to do a small update on a site for work with an Oracle back end.  I don’t work with Oracle so I ran into a little snag.  I needed to find the Oracle equivalent of SQL Server’s “SELECT TOP”.  So, here it is:

MS SQL

SELECT TOP 10
field1, field2
FROM
tablename
ORDER BY
field1

ORACLE

SELECT *
FROM
(SELECT
field1, field2
FROM
tablename
ORDER BY field1)
WHERE
ROWNUM <= 10

Leave a Comment