Introduction to access database paging method
Since there are many database records, the query results need to be displayed in pages. The following are two paging methods for the access database.
(Learning video sharing: Introduction to Programming)
1. Access query result paging method 1
1. Method
Suppose the number of records per page is CntPerPage. To obtain the query results on page Page, use the following SQL statement.
SELECT * FROM ( SELECT TOP CntPerPage * FROM( SELECT TOP Page*CntPerPage * FROM TableName WHERE Query_Conditionm ORDER BY OrderField ) ORDER BY OrderField DESC ) ORDER BY OrderField
TableName is the table name, Query_Condition is the query condition, and OrderField is the field name used for sorting
2. Principle
Nested three-step query:
First step query: Query the records of the current page and all previous pages, and sort them in descending order by the sort field
SELECT TOP Page*CntPerPage * FROM TableName WHERE Query_Conditionm ORDER BY OrderField
The second step query: Query the previous CntPerPage of the record just queried (already arranged in descending order) Query out the records (keep them in descending order). These are all the records on Page
SELECT TOP CntPerPage * FROM( 第一步查询结果 ) ORDER BY OrderField DESC
The third step of query: The previous query has actually queried all the records on Page, but in descending order. Arranged, this third step is just to put the data just obtained into a positive sequence. If the order is not required, or there are other data sorting processes in the program, then this step can be omitted.
SELECT * FROM ( 第二步查询结果 ) ORDER BY OrderField
3. Example
A Student table, you want to query all records whose age is less than 20 years old, sort by name, the number of records per page is 100, you want to get the query on page 5 As a result, use the following SQL statement.
SELECT * FROM (SELECT TOP 100 * FROM( SELECT TOP 500 * FROM Student WHERE age<20 ORDER BY name ) ORDER BY name DESC) ORDER BY name
2. NOT IN method commonly used on the Internet
When searching for paging methods on the Internet, this is the most common method.
Method:
SELECT TOP CntPerPage * FROM TableName WHERE Query_Conditionm AND id NOT IN ( SELECT TOP (Page-1)*CntPerPage id FROM TableName WHERE Query_Conditionm ORDER BY id ) ORDER BY id
Principle:
Two-step query:
First step: Select all eligible record IDs before this page
SELECT TOP (Page-1)*CntPerPage id FROM TableName WHERE Query_Conditionm ORDER BY id
Second Step: Add the query condition "id is not in the query results of the ids just selected" and get the first CntPerPage records. In this way, the query results will filter all the data on the first Page-1 page, and then select the data on Page-1. All records.
SELECT TOP CntPerPage * FROM TableName WHERE Query_Conditionm AND id NOT IN (第一步查询结果) ORDER BY id
3. Paging query efficiency
The actual test efficiency of the two methods is almost the same, but I personally think that the efficiency of the NOT IN judgment in the second method should not be too high, so I feel that if the amount of records is relatively large, the first method should be more efficient.
Related recommendations: access database tutorial
The above is the detailed content of Introduction to access database paging method. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The advantage of multithreading is that it can improve performance and resource utilization, especially for processing large amounts of data or performing time-consuming operations. It allows multiple tasks to be performed simultaneously, improving efficiency. However, too many threads can lead to performance degradation, so you need to carefully select the number of threads based on the number of CPU cores and task characteristics. In addition, multi-threaded programming involves challenges such as deadlock and race conditions, which need to be solved using synchronization mechanisms, and requires solid knowledge of concurrent programming, weighing the pros and cons and using them with caution.

How to avoid the third-party interface returning 403 error in the Node environment. When calling the third-party website interface using Node.js, you sometimes encounter the problem of returning 403 error. �...

The main reasons why you cannot log in to MySQL as root are permission problems, configuration file errors, password inconsistent, socket file problems, or firewall interception. The solution includes: check whether the bind-address parameter in the configuration file is configured correctly. Check whether the root user permissions have been modified or deleted and reset. Verify that the password is accurate, including case and special characters. Check socket file permission settings and paths. Check that the firewall blocks connections to the MySQL server.

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

SQL IF statements are used to conditionally execute SQL statements, with the syntax as: IF (condition) THEN {statement} ELSE {statement} END IF;. The condition can be any valid SQL expression, and if the condition is true, execute the THEN clause; if the condition is false, execute the ELSE clause. IF statements can be nested, allowing for more complex conditional checks.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Get ComponentVerify in EasyWechat5.5...
