Detailed introduction to the usage of limit and offset in MySQL

Big data learning monk 2022-02-13 07:18:21 阅读数:273

detailed introduction usage limit offset

Sometimes we use... In our study or work SQL sentence , So let's introduce limit and offset How to use .
mysql In general, you use limit To achieve , for example :

1、select* from user limit 3

It means to directly take the first three data

2、select * from user limit 1,3;

It means take 1 The last one 2,3,4 Three pieces of data

3、select * from user limit 3 offset 1;

It means take 1 Next 2,3,4 Three pieces of data

explain :

1、 When limit When followed by a parameter , This parameter indicates the number of data to be retrieved

for example select* from user limit 3 It means to directly take the first three data

2、 When limit When followed by two parameters , The first number represents the number to skip , The last digit indicates the quantity to be taken , for example

select * from user limit 1,3;

It's just skipping 1 Data , From 2 Data start to take , take 3 Data , That is to take 2,3,4 Three pieces of data

3、 When limit and offset When combined ,limit Only one parameter can be followed , Indicates the quantity to be taken ,offset Indicates the number to skip .

for example select * from user limit 3 offset 1; To skip 1 Data , From 2 Data start to take , take 3 Data , That is to take 2,3,4 Three pieces of data

copyright:author[Big data learning monk],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130718200295.html