I want to retrieve the last 20 rows that have been updated from a table in an Oracle database without using order by
then rownum function like
select *
from EMP
order by last_Updated
where rownum < 20
This query takes lot of time.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The query you posted doesn’t do what you think it does. That query will fetch 20 arbitrary rows and then order by the
last_updatedcolumn. If you want the 20 most recent rows, you’d need toORDER BY last_updatedin a nested query and then apply therownumpredicate in an outer query.Assuming that
last_updatedis indexed, that should be a very efficient query. You should be able to do a min/max scan on thelast_updatedindex and then do acount stopkeyto fetch only the first 20 rows. If you are having problems with the performance of this query, what sort of query plan are you getting?