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 8805627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:54:56+00:00 2026-06-14T01:54:56+00:00

In Oracle there is no limit, so I used this: SELECT * FROM (

  • 0

In Oracle there is no limit, so I used this:

SELECT * 
FROM ( 
     SELECT m.*, ROWNUM r 
     FROM TABLE_NAME m  
     WHERE COL LIKE XYZ 
     ORDER BY ID ASC
     ) 
WHERE r BETWEEN 10 AND 20;

But it is still not ordered. It is ordered in the 10 from 20, but not the entire table. How can I do that?

I want to ORDER THE ENTIRE TABLE with WHERE clause and get the ranged ones. The solution above only order within the range.


Maybe less confusing solution (in case anyone googled here):

SELECT a.* from (
  SELECT b.*, ROWNUM r FROM ( 
    SELECT * FROM table ORDER BY id ASC  
  ) b  WHERE  (city LIKE '%abc%' OR city IS NULL)
) a where r between 5 and 10

So it is a better idea to put order right in the middle criteria, and then put other criteria in the second level, and put row number in the outter-most level.

  • 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-14T01:54:58+00:00Added an answer on June 14, 2026 at 1:54 am

    You’ll need one more level of nesting as far as I know, something like:

    select b.* from (
     select a.*, rownum rnum from (
      select * from foo order by id
     ) a where rownum <= 20
    ) b where b.rnum >= 10;
    

    Demo:

    SQL> create table foo (id number);
    Table created.
    SQL> insert into foo
      2   select round(dbms_random.value(0, 1000))
      3   from dual
      4   connect by level <= 15;
    15 rows created.
    SQL> commit;
    Commit complete.
    

    rownum gets “materialized” before the ordering, so your approach cannot work, as you’ve noticed:

    SQL> select foo.*, rownum from foo order by id;
    
        ID     ROWNUM
    ---------- ----------
            24     15
           148      5
           151      2
           225      7
           234     11
           292      1
           305      4
           351      9
           383      8
           394     13
           426     12
           477     10
           553      6
           594     14
           917      3
    15 rows selected.
    

    So nest it once to get row numbers after ordering:

    SQL> select a.*, rownum from (
      2   select * from foo order by id
      3  ) a;
    
        ID     ROWNUM
    ---------- ----------
            24      1
           148      2
           151      3
           225      4
           234      5
           292      6
           305      7
           351      8
           383      9
           394     10
           426     11
           477     12
           553     13
           594     14
           917     15
    15 rows selected.
    

    But you can’t do a between with this though:

    SQL> select a.*, rownum from (
      2   select * from foo order by id
      3  ) a where rownum between 5 and 10;
    
    no rows selected
    

    This is because rownum gets a value only once a row enters the result set.
    And add a second layer to remove the first lines:

    SQL> select id, rnum from (
      2   select id, rownum rnum from (
      3    select id from foo order by id
      4   ) a where rownum <= 10
      5  ) b where b.rnum >= 5;
    
        ID   RNUM
    ---------- ----------
           234      5
           292      6
           305      7
           351      8
           383      9
           394     10
    
    6 rows selected.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to restore an Oracle 11g instance from raw data files
Is there a thin driver for Oracle available to be used with PHP (for
is there any way in Oracle, to get only the dd-mm-yyyy part from an
Given an Oracle Merge statement with a rejection limit, is there a shorthand way
Is there a way to make an Oracle query behave like it contains a
It appears that there is a limit of 1000 arguments in an Oracle SQL.
I have an Oracle database where I'm trying to select a user field from
There is a string, which comes from text field, and has 200 character limit.
In order to load data (from a CSV file) into an Oracle database, I
i am new to oracle.Already there is a store procedure which fetches data from

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.