Last Updated: 15 July, 2023
In MySQL, the LIMIT clause is used to restrict the number of results returned by a SELECT statement.
The LIMIT clause takes one or two numeric value arguments. The first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return.
The offset of the initial row is 0 that means first record of the table offset value is 0.
The basic syntax of the LIMIT clause is as follows:
SELECT column1, column2, ... FROM table_name [WHERE condition] [ORDER BY column1, column2, ...] LIMIT [offset,] row_count;
Here, row_count is the maximum number of rows to return, and offset is the number of rows to skip before beginning to return results. offset is an optional; if we don't specify it, the default value is 0, which means that the query will start from the first row.
To retrieve the first 4 rows from a table called student, we could use the following query:
SELECT * FROM student LIMIT 4;
To retrieve the three records from row 3 to 5 from a table called student, we could use the following query:
SELECT * FROM student LIMIT 2 OFFSET 3;
That's all, guys. I hope this MySQL article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com