php
MySQL LIMIT Data
The  MySQL LIMIT clause makes it easy to code multi page results or pagination with SQL, and is very useful on large tables. Returning a large number of records can impact on performance.

SELECT * FROM table_name LIMIT row_offset, row_count;

The LIMIT clause accepts one or two parameters which must be a nonnegative integer :

  • The first parameter specifies the offset of the first row to return i.e. the starting point.
  • The second parameter specifies the number of rows to return. The offset of the first row is 0 (not 1).

Where as, when only one parameter is given, it specifies the maximum number of rows to return from the beginning of the result set.

$sql = "SELECT * FROM student_detaile_2 LIMIT 3";

To retrieve the rows 2-4 (inclusive) of a result set, you can use the following query :

$sql = "SELECT * FROM persons LIMIT 1, 3";

The SQL query using the LIMIT clause in SELECT statement, after that we will execute this query through passing it to the PHP mysqli_query() function to get the limited number of records. Consider the following persons table inside the demo database :

idNameCollegeEmail IdMobile
1V V Ramana ReddyS V Arts and Science Collegeinfo@freetimelearning.com9963666068
2ChantiVidhyalaya Degree Collegefreetimelearn@gmail.com9010023210
3RamanaS V Universityvvramanareddy9963@gmail.com9966463846
4SureshAadhishankarasureshreddy@gmail.com9700900292
5Suman ReddyPriyadharshinisumanreddy.mca@gmail.com9966395199