Differences between the paging query statements of Oracle, MySQL, and SqlServe databases: oraclesqlserve

Source: Internet
Author: User

Differences between the paging query statements of Oracle, MySQL, and SqlServe databases: oraclesqlserve

First, define the parameters to be used in the paging statement:

Int currentPage; // current page
Int pageRecord; // number of records displayed per page

Take the ADDRESSBOOK data table as an example (10 records are displayed on each page ):

I. SqlServe paging statement for downloading

String SQL = "select top" + pageRecord + "* from addressbook where id not in (select top" + (currentPage-) * pageRecord + "id from t_user )"; // (currentPage-) * pageRecord: indicates the number of records starting from

Page 2 SQL Demo:

select top 20 * from addressbook where id not in (select top 10 id from addressbook)

Ii. MySQL database paging statements

String SQL = "select * from addressbook where limit" + (currentPage-) * pageRecord + "," + pageRecord + ""; // select * from table name [condition] limit M, N; // M indicates the number of records starting from, for example, each page displays a record, on the second page, you must start from the record. // N: the number of data records read on each page.

Page 2 SQL Demo:

select * from addressbook where limit 10,10

Iii. Oracle Database paging statements

String sqls = "select * from ( select rownum rn,t.* from addressbook t where rownum <= "+currentPage*pageRecord+" ) where rownum > "+(currentPage -1)*pageRecord; 

Page 2 SQL Demo:

select * from ( select rownum rn,t.* from addressbook where rownum<= 20 ) where rownum > 10

The above section describes the differences between the paging query statements of Oracle, MySQL, and SqlServe databases. I hope this will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.