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

  • Home
  • SEARCH
  • 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 8787187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:49:26+00:00 2026-06-13T21:49:26+00:00

In MySql, the concept of pagination can easily be implemented with a single SQL

  • 0

In MySql, the concept of pagination can easily be implemented with a single SQL statement using the LIMIT clause something like the following.

SELECT country_id, country_name 
FROM country c 
ORDER BY country_id DESC 
LIMIT 4, 5;

It would retrieve the rows starting from 5 to 10 in the result set which the SQL query retrieves.


In Oracle, the same thing can be achieved using row numbers with a subquery making the task somewhat tedious as follows.

SELECT country_id, country_name
FROM
  (SELECT rownum as row_num, country_id, country_name
   FROM
    (SELECT country_id, country_name
     FROM country
     ORDER BY country_id desc)
  WHERE rownum <= 10
  )
WHERE row_num >=5;

In Oracle 10g (or higher, I’m not sure about the higher versions though), this can be made somewhat easy such as,

SELECT country_id, country_name
  FROM (SELECT country_id, country_name, row_number() over (order by country_id desc) rank
      FROM country)
 WHERE rank BETWEEN 6 AND 10;

Regarding an application like a web application, the concept of pagination is required to implement almost everywhere and writing such SQL statements every time a (select) query is executed is sometimes a tedious job.

Suppose, I have a web application using Java. If I use the Hibernate framework then there is a direct way to do so using some methods supported by Hibernate like,

List<Country>countryList=session.createQuery("from Country order by countryId desc")
.setFirstResult(4).setMaxResults(5).list();

but when I simply use JDBC connectivity with Oracle like,

String connectionURL = "jdbc:oracle:thin:@localhost:1521:xe";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;

Class.forName("oracle.jdbc.OracleDriver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT * from country");

My question in this case, is there a precise way to retrieve a specified range of rows using this code? Like in the preceding case using the methods something like setFirstResult() and setMaxResults()? or the only way to achieve this is by using those subqueries as specified.

  • 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-13T21:49:27+00:00Added an answer on June 13, 2026 at 9:49 pm

    Because ‘No’ is an answer too:

    Unfortunately, you will have to use the subquery approach. I would personally use the one with the rank (the second one).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Mysql's environment is following: character_set_database=big5 And when I send a SQL which contains tranditional
I have a MySQL Table that looks like this: The SQL to create the
I am building a Web2Print website using PHP, MySQL and jQuery.The main concept of
In mysql I can set default value for column like this: ALTER TABLE <Table>
I'm building a webapp using php, ajax, javascript, mysql. I've been worring about something
I have the following SQL query: SELECT DISTINCT business_key FROM Memory WHERE concept <>
Mysql supports prepared statements in this way: http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html Is there a support for it
MySQL connection in PHP can be established in two ways: $mysql = new mysqli('localhost',
I don't know this concept is there or not. Can we store the Files
I am learning OOPS concept and also using PDO , but really stuck in

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.