How to get the article M in the table to nth record (n greater than M) for the three major databases

Source: Internet
Author: User

Database fetch table M to nth record (n>m)

1. Oracle Database: (Note: refers to TableName's primary key)


(select Tablename.*,rownum as con from tableName

where RowNum <= m


where con >= n;

2. SQL Server database: (Note: refers to the primary key of the TableName)

Realization Principle Explanation:

1) first to detect the first M noodle Records

2) re-detect the top n Noodle Records

3) Finally filter out the previous m record by condition

Method One:

Select Top N-m+1 * from TableName

where not in

(select top m from TableName ORDER by Desc


Method Two:

Select Top N-m+1 * from TableName as a where not exists


(select top M * from TableName ORDER BY id DESC) b

where =


3. mysql Database:

SELECT * from TableName limit m, N;

This article is from the "focus on Development Technology" blog, please be sure to keep this source

How to get the article M in the table to nth record (n greater than M) for the three major databases

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: 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.