Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to query the first 10 records by mysql

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to query the first 10 records in mysql". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to query the top 10 records by mysql.

In mysql, the first 10 records can be queried using the SELECT query statement and the limit keyword, with the syntax "SELECT * FROM data table LIMIT 10;" or "SELECT * FROM data table LIMIT 010;".

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

In mysql, you can use the select statement and the limit keyword to query the first 10 records.

In MySQL, you can use SELECT statements to query data. Query data refers to the use of different query methods to obtain different data from the database according to the requirements, which is the most frequent and important operation.

LIMIT is used to specify which records the query results are displayed from and how many records are displayed.

Syntax:

SELECT {* |} FROM, … [LIMIT clause]

The syntax of the LIMIT clause:

1. Do not specify the initial position

Number of LIMIT records

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.

"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:

Mysql > SELECT * FROM tb_students_info LIMIT 10 +-+ | 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 | 9 | Thomas | 3 | 22 | M | 2016-06-07 | | | 10 | Tom | 4 | 23 | M | 165,165 | 2016-08-05 | +-+ 10 rows in set (0.26sec) |

2. Specify the initial position

LIMIT initial position, number of records

The LIMIT keyword specifies the record from which the query results are displayed and how many records are displayed.

"initial position" indicates the record from which the display begins.

"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.

Mysql > SELECT * FROM tb_students_info LIMIT 0je 10 +-+ | 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 | 9 | Thomas | 3 | 22 | M | 2016-06-07 | | | 10 | Tom | 4 | 23 | M | 165,165 | 2016-08-05 | +-+ 10 rows in set (0.26 sec) so far | I believe you have a deeper understanding of "how to query the top 10 records of mysql", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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: 234

*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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report