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

The main method of data query with specified number of items in mysql Database

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the main methods of mysql database specified number of data query, the contents of the article are carefully selected and edited by the author, with a certain pertinence, for everyone's reference significance is still relatively great, the following with the author to understand the main methods of mysql database specified number of data query.

1. SQL queries the first 10 data records:

Select top X * from table_name order by colum_name desc

Query the first X records, can be changed to the desired number, such as the first 10. Sort the first X records of the query by colum_name attribute descending order, followed by "order by" followed by the attribute column name to be sorted, where desc represents descending order and asc represents ascending order (the default is also ascending order, mysql does not support top).

Select * from table_name limit 0pl 10

-usually 0 can be omitted and written directly as limit 10. 0 means to start after the 0 record, that is, from the first.

2. When querying articles N to M records, paging is often used.

Select top n from (select top m from table_name order by column_name asc) an order by column_name desc

(note the data order. Mysql does not support top)

Select * from table_name limit 5 and 10

-- starting from the record after Article 5, 10 is the offset. That is to say, starting with Article 5, take 10 records. (that is, intercept 10 records after section 5 in the database)

3. Query the data between the data values of the specified field

SELECT * FROM user WHERE uid BETWEEN value1 AND value2

After reading the above about the main methods of querying the specified number of data in mysql database, many readers must have some understanding. If you need to get more industry knowledge and information, you can continue to follow our industry information column.

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.

Share To

Database

Wechat

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

12
Report