Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7767107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:35:37+00:00 2026-06-01T15:35:37+00:00

I want to use this SQL query to get only the records between 8

  • 0

I want to use this SQL query to get only the records between 8 and 10:

select *
from(
SELECT a.*,rownum rn 
FROM ACTIVESESSIONSLOG  a
ORDER BY USERID ASC)
WHERE rn  >= 8 and rn <= 10

When I implement this SQL query into pagination I get every time 1 row on the second page no matter how many rows I have configured to be displayed into the pages. Is this SQL query valid?

This is the table structure:

-- TABLE ACTIVESESSIONSLOG

CREATE TABLE ACTIVESESSIONSLOG(
  ASESSIONID VARCHAR2(30 ) NOT NULL,
  USERID VARCHAR2(30 ),
  ACTIVITYSTART TIMESTAMP(6),
  ACTIVITYEND TIMESTAMP(6),
  ACTIVITY CLOB
)
/

Best wishes

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:35:38+00:00Added an answer on June 1, 2026 at 3:35 pm

    rownum is applied before the ORDER BY so your query is almost certainly not doing what you expect. Your query is essentially asking for an arbitrary 3 rows and the ORDER BY isn’t doing anything useful.

    You could use the analytic function row_number instead, i.e.

    SELECT *
      FROM (SELECT a.*,
                   row_number() over (order by userid asc) rn
              FROM activeSessionsLog a)
     WHERE rn BETWEEN 8 AND 10
    

    which will page through the results

    SQL> ed
    Wrote file afiedt.buf
    
      1  select empno, ename, job
      2    from (select e.*,
      3                 row_number() over (order by empno) rn
      4            from emp e)
      5*  where rn between 1 and 3
    SQL> /
    
         EMPNO ENAME      JOB
    ---------- ---------- ---------
          7369 SMITH      CLERK
          7499 ALLEN      SALESMAN
          7521 WARD       SALESMAN
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  select empno, ename, job
      2    from (select e.*,
      3                 row_number() over (order by empno) rn
      4            from emp e)
      5*  where rn between 4 and 8
    SQL> /
    
         EMPNO ENAME      JOB
    ---------- ---------- ---------
          7566 JONES      MANAGER
          7654 MARTIN     SALESMAN
          7698 BLAKE      MANAGER
          7782 CLARK      MANAGER
          7788 SCOTT      ANALYST
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  select empno, ename, job
      2    from (select e.*,
      3                 row_number() over (order by empno) rn
      4            from emp e)
      5*  where rn between 9 and 11
    SQL> /
    
         EMPNO ENAME      JOB
    ---------- ---------- ---------
          7839 KING       PRESIDENT
          7844 TURNER     SALESMAN
          7876 ADAMS      CLERK
    

    It may be more efficient, however, to do something like this where Oracle can use the inner rownum <= 10 predicate to know that it can stop sorting the data once it has identified the first 10 rows.

    SELECT c.*
      FROM (SELECT b.*, rownum rn
              FROM (SELECT a.*
                      FROM activeSessionsLog a
                     ORDER BY userid asc) b
             WHERE rownum <= 10) c
     WHERE rn >= 8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get 1000 records from a table randomly, so I use: SELECT
I want to use this regular expression in Python: <(?:[^]*[']*|'[^']*'[']*|[^'>])+> (from RegEx match open
I have a query that, basically, says this: SELECT DISTINCT [DB_ID] FROM [TableX] WHERE
I want to get only status = 1 records. But I don't have status
I want to perform a simple sql query but cannot manage to get it
Looking at similar questions, I actually want the exact opposite of this: SQL query
I want to use this function EnumWindows(EnumWindowsProc, NULL);. The EnumWindowsProc is a Callback function:
I want to use this for an object factory: Given a string, create a
I want to use this C code in my C++ project : mysql.c :
I want to use this line of code: using (ADataContext _dc = new ADataContext(ConnectionString),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.