SQL statement for querying by page in Oracle Database

Source: Internet
Author: User
Tags mysql tutorial

SQL statement for querying by page in Oracle Database

Query SQL statements by page in the oracle database tutorial
Oracle
Select *
From (select rownum r, t1. * from table name t1 where rownum <m + n) t2
Where t2.r> = m

For example, to retrieve 10 or 20 records from the table sys_option (primary key: sys_id), the statement is as follows:

Select *
From (select rownum r, t1. * from sys_option where rownum <30) t2
Where t2.r> = 10

Mysql tutorial
Select * from table name limit m, n
Retrieve 10 or 20 records from the table sys_option (primary key: sys_id)
Select * from sys_option limit 10, 20

Sqlserver
Obtain n records starting from the m record in the database table. Use the keyword top: It is worth noting that if the select statement contains both top and order, select from the sorted results:
Select *
From (select top n * from
(Select top (m + N-1) * from table_name order by primary key desc) tbl_1) tbl_2
Order by primary key asc

Example here :( retrieve 10 or 20 records from the table sys_option (primary key is sys_id)
Select *
From (select top 20 *
From (select top 29 * from sys_option order by sys_id desc) t1) t2
Order by sys_id asc

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.