Assuming that there is a need to display, out of a number of about 30 records:
- the first five for the first place,
- the next 10 for the second place and
- another 14 for the third place.
This can be easily done in MySQL by using of LIMIT and OFFSET.
1 2 3 |
-- First 5 recordings SELECT * FROM customers LIMIT 5; |
1 2 3 4 |
-- Next 10 records SELECT * FROM customers LIMIT 5,10; -- or SELECT * FROM customers LIMIT 10 OFFSET 5; |
In the simple version, it can be seen that the position from which the display starts is passed first, then the record limit, second. It can also be noted that the position from which the extraction actually starts is from offset+1.
1 2 3 4 |
-- Next 14 records SELECT * FROM customers LIMIT 15,14; -- or SELECT * FROM customers LIMIT 14 OFFSET 15; |
They will be extracted up to position 29, but to save space, I shortened the image…
Source: w3Schools.com