In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
SQL has several ways to achieve paging, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
In the vast majority of applications, it is common to return a large number of eligible records, the most typical of which is search. In the application of search, the user gives the search conditions, and the server finds out the records that meet the conditions. But often the search will return a large number of data records, if in the web page, it is often achieved through paging, the page provides buttons such as the previous page, the next page and so on to achieve paging. The following editor will explain that there are several ways to achieve paging in SQL.
Find method of 1.EJB
two。 All records are placed in the collection object before the first page is displayed, and subsequent pages are fetched in memory.
3. Each page makes a repeated query to the database, and then displays the records that meet the criteria.
4. The search results of the first few pages are saved in memory (frequently used), and subsequent records (which most users do not have the patience to read) are obtained by connecting to the database.
5. Various other cache mechanisms.
We can choose the method that suits us according to the actual situation. I'll introduce you to a standard SQL statement to get qualified data. Such as the records that meet the conditions (in the where statement) from articles 10 to 20. A necessary condition for obtaining records in this way is that there must be a field that identifies the order of the records, such as id,time, and so on. Let me show you an example:
There are several ways for SQL to achieve paging
Query items 10 to 20 of all records in the t _ table table, sorted by id.
The SQL statement is:
SELECT * FROM t_table T1 WHERE (SELECT count (*) FROM t_table T2 WHERE t2.id)
< t1.id ) >= 10 AND (SELECT count (*) FROM t_table T2 WHERE t2.id)
< t1.id ) < 20 又如查询t_table表中key='123'第10到20条的记录,按id排序。 SELECT * FROM t_table t1 WHERE (SELECT count(*) FROM t_table t2 WHERE t2.id < t1.id AND t2.key = '123') >= 10 AND (SELECT count (*) FROM t_table T2 WHERE t2.id < t1.id AND t2.key = '123') < 20 AND t1.key = '123' of course the id in the condition can be replaced with any field that can identify the order of records.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Cat / app/redis/config/redis_6380.conf # INCLUDES # include / p
© 2024 shulou.com SLNews company. All rights reserved.