Hi all,
In SQL Server 7.0, I can get top 5 records order by date very easy with this syntax:
SELECT TOP 5 column1 FROM table1
WHERE condition1
ORDER BY column2
But in Oracle8, I don't know how to do that. Someone can help me? MCSD BW.
You could user the rownum virtual column. This column is not part of any table, but every time a SQL gets executed, a row number (rownum) is associated with each row from the result set. So you could do this to get the first five rows for your SQL:
select * from
(SELECT column1 FROM table1
WHERE condition1
ORDER BY column2)
where rownum < 6;
I wrapped your query into this outer SQL because Oracle has first to execute the ORDER BY on all the inner select before being able to give you the first five rows. If I had put the "where rownum < 6" in your SQL directly, Oracle would have sorted only the first five rows of the result sets.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.