Assuming that the current page is PageNo, and each page has PageSize records, now use Mysql, Oracle, and SQL Server to query the student table by paging. 1. Mysql paging query
SELECT * FROM student LIMIT (PageNo - 1) * PageSize,PageSize;
Understanding: (Limit n,m) => Take m records from the nth row, and n starts from 0.
2. Oracle's paging query:
SELECT * FROM ( SELECT ROWNUM rn ,* FROM student WHERE Rownum <= pageNo * pageSize ) WHERE rn > (pageNo - 1) * pageSize
Understanding: Assuming pageNo = 1, pageSize = 10, first retrieve records with row numbers less than or equal to 10 from the student table, and then retrieve records with rn greater than 0 from these records to achieve paging purposes. ROWNUM starts at 1.
3. SQL Server paging query:
SELECT TOP PageSize * FROM ( SELECT ROW_NUMBER () OVER (ORDER BY id ASC) RowNumber ,* FROM student ) A WHERE A.RowNumber > (PageNo - 1) * PageSize
Understanding: Assuming pageNo = 1, pageSize = 10, first sort according to the id of the student table in ascending order, rownumber as the row number, and then take out 10 records starting from row 1.
Some databases may have several methods for paging query, and the query method written here may not be the most efficient query method, but this is the most convenient paging query I use. If you are interested, you can also study other paging query methods.