SELECT with a LIMIT clause use for Paging in MySQL

Use paging with help of LIMIT clause in Select query in MYSQL

LIMIT is used as paging purpose also, we can limit the number of rows with select statement. When a LIMIT clause contains two numbers, it is used as LIMIT offset, count. So it will skip the offset mentioned rows and return the COUNT rows as output.

Check the use of Limit clause with one parameter.
It will return number of rows as mentioned as one parameter.

SELECT id, name, population
FROM city ORDER BY id
LIMIT 5;

+----+----------------+------------+
| id | name           | population |
+----+----------------+------------+
|  1 | Kabul          |    1780000 |
|  2 | Qandahar       |     237500 |
|  3 | Herat          |     186800 |
|  4 | Mazar-e-Sharif |     127800 |
|  5 | Amsterdam      |     731200 |
+----+----------------+------------+

Example of LIMIT clause with two numbers:

SELECT id, name, population
FROM city ORDER BY id
LIMIT 3, 5;

+----+----------------+------------+
| id | name           | population |
+----+----------------+------------+
|  4 | Mazar-e-Sharif |     127800 |
|  5 | Amsterdam      |     731200 |
|  6 | Rotterdam      |     593321 |
|  7 | Haag           |     440900 |
|  8 | Utrecht        |     234323 |
+----+----------------+------------+

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.