In this article we will see "How to use LIMIT in MySql" to get limited data in a table and "LIMIT query syntax with example".

LIMIT query in MySql syntax

The LIMIT statement is used to get limited data in a table, syntax is as follows:


/*returns top rows*/
SELECT * FROM tableName LIMIT numberOfRows;

/*returns rows in a range*/
SELECT * FROM tableName LIMIT startIndex,numberOfRows;


LIMIT query in MySql example

The LIMIT statement is used to get limited data in a table, as shown below:


/*Example EMPLOYEE table */
+----+--------+---------+
| id | name   | email   |
+----+--------+---------+
|  1 | name-1 | email-1 |
|  2 | name-2 | email-2 |
|  3 | name-3 | email-3 |
|  4 | name-4 | email-4 |
|  5 | name-1 | email-5 |
|  6 | name-2 | email-6 |
+----+--------+---------+



We will now apply LIMIT on above table to get top rows and rows in a range:


/*returns top rows*/
SELECT * FROM EMPLOYEE LIMIT 1;

/*returns rows in a range*/
SELECT * FROM EMPLOYEE LIMIT 2,3;

Output: Output will be something like this:


/*returns top rows*/
+----+--------+---------+
| id | name   | email   |
+----+--------+---------+
|  1 | name-1 | email-1 |
+----+--------+---------+

/*returns rows in a range*/
+----+--------+---------+
| id | name   | email   |
+----+--------+---------+
|  3 | name-3 | email-3 |
|  5 | name-1 | email-5 |
|  6 | name-2 | email-6 |
+----+--------+---------+


In this article we have seen "How to use LIMIT in MySql" to get limited data in a table and "LIMIT query syntax with example", in upcoming articles we will see more about Mysql syntax and queries with example.
  • By Techburps.com
  • Oct 20, 2017
  • MySql