What are the usages of limit in MySQL (recommended)

What are the usages of limit in MySQL (recommended)
SELECT * FROM table name limit m,n;
SELECT * FROM table LIMIT [offset,] rows;

1. m means starting the search from the m+1th row, and n means retrieving n pieces of data. (m can be set to 0)

For example: SELECT * FROM 表名limit 6,5;

Means: starting from the 7th record line, take out 5 data

2. It is worth noting that n can be set to -1. When n is -1, it means starting the search from row m+1 until the last piece of data is retrieved.

For example: SELECT * FROM 表名limit 6,-1;

It means: take out all the data after the 6th record line.

3. If only m is given, it means taking out a total of m records starting from the first record line.

For example: SELECT * FROM 表名limit 6;

Means: Get the first 6 rows.

4. Select the corresponding statement according to the amount of data:

a.Offset is relatively small:

SELECT * FROM aff limit 10,10

After multiple runs, the time remained between 0.0004-0.0005

SELECT * FROM aff Where vid >=(
SELECT vid From aff Order By vid limit 10,1
) limit 10

After multiple runs, the time remained between 0.0005-0.0006, mainly 0.0006

Conclusion: When the offset is small, it is better to use limit directly. This display is the reason for the subquery.

b. When the offset is large.

SELECT * FROM aff limit 10000,10

After multiple runs, the time remains around 0.0187

SELECT * FROM aff Where vid >=(
SELECT vid FROM aff Order By vid limit 10000,1
) limit 10

After multiple runs, the time remained at around 0.0061, which is only 1/3 of the former.

Conclusion: The larger the offset, the better the latter.

Summarize

The above is the usage of limit in MySQL that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Detailed explanation of MySQL limit usage and performance analysis of paging query statements
  • Usage and points to note of mysql limit paging
  • In-depth analysis of the use of limit in Mysql
  • Detailed explanation of MySQL limit classic usage and optimization examples
  • In-depth analysis of the usage of limit in mysql
  • Detailed explanation and precautions of limit usage in MySQL

<<:  How to increase your web performance by 3 times by turning on a parameter in Nginx

>>:  CocosCreator Getting Started Tutorial: Making Your First Game with TS

Recommend

Is it necessary to give alt attribute to img image tag?

Do you add an alt attribute to the img image tag? ...

What to do if you forget your Linux/Mac MySQL password

What to do if you forget your Linux/Mac MySQL pas...

How to allow external network access to mysql and modify mysql account password

The root account of mysql, I usually use localhos...

In-depth explanation of iterators in ECMAScript

Table of contents Preface Earlier iterations Iter...

MySQL merge and split by specified characters example tutorial

Preface Merging or splitting by specified charact...

MySQL 8.0.17 installation and simple configuration tutorial under macOS

If you don’t understand what I wrote, there may b...

Quickly solve the Chinese input method problem under Linux

Background: I'm working on asset reporting re...

MySQL password modification example detailed explanation

MySQL password modification example detailed expl...

An article teaches you JS function inheritance

Table of contents 1. Introduction: 2. Prototype c...

How to convert JavaScript array into tree structure

1. Demand The backend provides such data for the ...

Solutions to MySQL OOM (memory overflow)

OOM stands for "Out Of Memory", which m...

React method of displaying data in pages

Table of contents Parent component listBox List c...

Invalid solution when defining multiple class attributes in HTML

In the process of writing HTML, we often define mu...

Native JavaScript implementation of progress bar

The specific code for JavaScript to implement the...