This tutorial explains how to use limit clause within MySQL query to fetch records. The MySQL LIMIT clause is used to limit the number of records returned from MySQL query by using value passed with LIMIT clause. Limit clause is used with the SELECT statement to constrain the number of records returned in result set.
Limit clause takes one or two numeric arguments, The values for both arguments are only positive integers.
LIMIT offset, count
offset : Defines the offset of first row to return.(default value is 0) count : Defines the maximum number of records to return.
Note : If only single argument is passed in query than offset used its default value.
LIMIT 0, 5
In the above both examples, Both queries returns the first five records from users table.
Get Records with in Range Example :
LIMIT 10, 5
In the above example query returns the rows between the range starting from 10th row upto 14th row. In the query offset is set with value 10 and count value is 5. So the query start fetching records from 10th row and fetch 5 rows in result set.