Common database page SQL statement

xiaoxiao2021-03-06  99

When writing a system and web application, we involve interaction with the database. If the amount of data in the database is large, all records have been retrieved, which will take up a large resource of the system, so we often use, need How many data is only taken from the database, ie, using a paged statement. According to the content used by yourself, put the common database SQL Server, Oracle, and My SQL's pagper, starting N-recorded statements from the m-data data from the database table summary: SQL Server from the Mth in the database table Record starts to take N records, use Top keyword: note that if there is both TOP in the SELECT statement, there is ORDER BY, it is selected from the sorted result set: SELECT * FROM (SELECT TOP (M N - 1) * from the list name ORDER BY Primary key DESC) T1) T2 Order BY Primary key ASC, for example, from 10 records from 10 records or retrieves 20 records from table SYS_OPTION (primary key SYS_ID), the statement is as follows: SELECT * FROP (SELECT TOP 20 * from (SELECT TOP 29 * from sys_option order by sys_id) T1) T2 Order by Sys_ID ASC ORCE Database From the Mth Record in the Database Table Start Search N: SELECT * FROM (SELECT ROWNUM R, T1. * FROM Name T1 WHERE ROWNUM = m For example, from 10 records from 10 records or 20 records from table SYS_OPTION (primary key SYS_ID), the statement is as follows: SELECT * FROM (SELECT ROWNUM R (SELECT ROWNUM R) * From Sys_Option WHERE ROWNUM <30) T2 WHERE T2.R> = 10 My SQL Database MY SQL Database is the easiest, using mysql's LIMIT function, limit [offset,] ROWS starts searching N records from the M string record in the database table The statement is: SELECT * FROM Table Name LIMIT M, N, for example, from 10 records from 10 records or retrieves 20 records from table sys_option (primary key SYS_ID), the statement is as follows: SELECT * from Sys_Option Limit 10, 20

转载请注明原文地址:https://www.9cbs.com/read-97468.html

New Post(0)