some people suggest to use this query :
select *
from employees
where rownum <= 10
order by salary;
but the problem with this will return a random set of ten rows ordered by salary which is not what I need.
Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers 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.
You can use a subquery for this like
[code]
select *
from
( select *
from emp
order by sal desc )
where ROWNUM <= 5;
[/code]
Starting from Oracle 12c R1 (12.1). there is a syntax available to limit rows or start at offsets (full syntax here)
example :
[code]
SELECT *
FROM employees
ORDER BY salary
OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY;
[/code]
hope this helpful 🙂