Database fetch table M to nth record (n>m)
1. Oracle Database: (Note: Tablename.id refers to TableName's primary key)
SELECT * FROM
(select Tablename.*,rownum as con from tableName
where RowNum <= m
ORDER BY tablename.id Desc)
where con >= n;
2. SQL Server database: (Note: Tablename.id 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 Tablename.id not in
(select top m tablename.id from TableName ORDER by Desc Tablename.id)
ORDER BY Tablename.id
Method Two:
Select Top N-m+1 * from TableName as a where not exists
(SELECT * FROM
(select top M * from TableName ORDER BY id DESC) b
where b.id = a.id)
ORDER BY id DESC
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 http://bingge2015.blog.51cto.com/4332222/1847492
How to get the article M in the table to nth record (n greater than M) for the three major databases