Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Location
    India
    Posts
    15

    Question Unanswered: Selecting a specific portion of records from a query

    Suppose, I've executed a select query which results say 1000 records.
    I want to fetch these records in multiple resultsets.

    That is, I may want to get only from 1st to 50th record;
    or from 600th to 800th record likewise...
    (Better take the example of a search engine, which displays the results in
    multiple pages).

    And I want to specify this range in the query itself.
    First of all, is it possible? If yes then how?

    Anybody please explain the syntax for the above sql query.

    Srinivas K
    Last edited by srinivas_vja; 05-25-05 at 09:10. Reason: to increase views

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Yes, this is commonly requried for pagination in web-based apps:
    Code:
    select ename, deptno, job
    from
    ( select ename, deptno, job, rownum rn
      from
      ( select ename, deptno, job
        from emp
        order by ename
      ) where rownum <= :last_rec
    ) where rn >= :first_rec;
    Just set the bind variables :first_rec and :last_rec to the required values and run the query.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •