To select 5 records, You may use rownum in your where clause like rownum <= 5. So far as TOP is concerned you may sort your output in desc or asc ...
e.g
select * from employee
where ronum <= 5
order by emp_id desc
This topic has come up previously. A good reference is thread185-114597.
Kindus's suggestion to add an "order by" clause to the query in order to get the largest emp_ids isn't quite correct. The problem is that Oracle does the order by after applying the where clause, not before. Carp addresses this issue in the earlier thread. If you are on Oracle 8i you can use the technique of embedding the order by clause in a subselect. I think the resulting query would be
SELECT id_person from
(select id_person from PERSON order by id_person desc)
where rownum < 6;
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.