MySQL Limit

 

The LIMIT clause, as you might guess, is used to limit the number of rows returned in the result set. It has two parameters or arguments. The first parameter is offset which tells mysql how many rows to skip before starting to retrieve. The second parameter is count which tells mysql how many rows to retrieve.

SELECT 
    column_name1,column_name2,...
FROM
    table_name
LIMIT offset , count;

Here is an example.

As you can see here, the offset is 2 which means mysql will skip row one and two and start retrieving from row number 3. The count is 5 which means it will retrieve 5 rows. As a result, you see rows [3,4,5,6,and 7].

Offset is optional

The offset argument is optional. If you don’t use an offset then offset will be default to zero.

SELECT 
    column_name1,column_name2,...
FROM
    table_name
LIMIT count;

The query above is the same as the query below.

SELECT 
    column_name1,column_name2,...
FROM
    table_name
LIMIT 0, count;

Here is an example

LIMIT without the offset argument, just the count argument.

 

 




Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!

required
required


Leave a Reply

Your email address will not be published.