In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
How to query items 2 to 4 of data by mysql? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!
In mysql, you can use the "LIMIT" keyword to query the second to fourth pieces of data, the specific statement is "SELECT * FROM data table name LIMIT 1jin3;", query the three records starting from the second record. The LIMIT keyword specifies the record from which the query results are displayed and how many records are displayed.
When there are tens of thousands of data in the data table, querying all the data in the table at once will reduce the speed of data return and cause great pressure on the database server. At this point, you can use the LIMIT keyword to limit the number of entries returned by the query results.
LIMIT is a special keyword in MySQL that specifies which record the query results are displayed from and how many records are displayed.
Specify initial location
The LIMIT keyword specifies the record from which the query results are displayed and how many records are displayed.
The basic syntax format for LIMIT to specify the initial location is as follows:
LIMIT initial position, number of records
Where the "initial position" indicates the record from which the display starts, and the "number of records" indicates the number of records displayed. The position of the first record is 0 and the position of the second record is 1. The following records are in turn and so on.
Note: both parameters after LIMIT must be positive integers.
Example 1
In the tb_students_info table, use the LIMIT clause to return a record with 3 rows starting with record 2. The SQL statement and run results are as follows.
Mysql > SELECT * FROM tb_students_info LIMIT 1pr 3 +-+ | id | name | dept_id | age | sex | height | login_date | +- -+-- + | 2 | Green | 3 | 23 | F | 2016 | 10-22 | 3 | Henry | 2 | 23 | M | 2015-05-31 | 4 | Jane | 1 | 22 | F | 2016-12-20 | + -+ 5 rows in set (0.00 sec)
As you can see from the result, the statement returns the next three records starting with the second record. The first number "1" after the LIMIT keyword indicates the beginning of line 2 (the position of the record starts at 0, and the position of line 2 is 1), and the second number 3 indicates the number of rows returned.
Do not specify the initial position
When the LIMIT keyword does not specify the initial position, the record is displayed from the first record. The number of records displayed is specified by the LIMIT keyword.
The basic syntax format in which LIMIT does not specify the initial location is as follows:
Number of LIMIT records
Where "number of records" indicates the number of records displayed. If the value of the number of records is less than the total number of query results, the specified number of records are displayed starting with the first record. If the value of the number of records is greater than the total number of query results, all records from the query are directly displayed.
Example
The first 8 rows of the tb_students_info query results are displayed. The SQL statement and run results are as follows.
Mysql > SELECT * FROM tb_students_info LIMIT 8 +-+ | id | name | dept_id | age | sex | height | login_date | +- -+-+ | 1 | Dany | 1 | 25 | F | 2015 | 09-10 | 2 | Green | 3 | 23 | F | 2016-10-22 | 3 | Henry | 2 | 23 | M | 2015-05-31 | 4 | Jane | 1 | 22 | F | 2016-12-20 | 5 | Jim | | 1 | 24 | M | 2016 | 01-15 | | 6 | John | 2 | 21 | M | 2015 | 11-11 | 7 | Lily | 6 | 22 | F | 2016-02-26 | 8 | Susan | 4 | 23 | F | 2015-10-01 | +-+ -+ 4 rows in set (0.00 sec)
Only 8 records are displayed in the result, indicating that "LIMIT 8" limits the number of records displayed to 8.
LIMIT with one parameter specifies that it starts at the first row of the query result, and the only parameter indicates the number of rows returned, that is, "LIMIT n" returns the same result as "LIMIT 0line n". LIMIT with two parameters returns data that starts at a specified number of rows from anywhere.
Thank you for reading! After reading the above, do you have a general idea of how mysql queries items 2 to 4 of data? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.
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
© 2024 shulou.com SLNews company. All rights reserved.