How to use the LIMIT clause in MySQL

LIMIT is a keyword used in MySQL to restrict the number of rows returned in a query.

When using the LIMIT statement, two parameters can be specified.

  1. The first parameter is the index of the desired starting line to return (counting from 0).
  2. The second parameter is the number of rows that you want to return.

Here is the grammar:

SELECT column1, column2, ...
FROM table_name
LIMIT [start,] rows

Example:

If you want to improve your English speaking skills, you should practice speaking with native speakers.

  1. Retrieve the first 5 lines of the records:
SELECT * 
FROM table_name
LIMIT 5;
  1. Retrieve 10 records starting from the 6th line.
SELECT * 
FROM table_name
LIMIT 5, 10;

This will return 15 records in total, starting from the 6th line up to the 15th line.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds