Reprence Html CSS javascript PHP MySQL Bootsrap

The MySQL LIMIT Clause

The LIMIT clause is used to specify the number of records to return.

The LIMIT clause is useful on large tables with thousands of records. Returning a large number of records can impact performance.



LIMIT Syntax
40

Demo Database

Below is a selection from the "Customers" table in the Northwind sample database:

41

MySQL LIMIT Examples

The following SQL statement selects the first three records from the "Customers" table:


What if we want to select records 4 - 6 (inclusive)?

MySQL provides a way to handle this: by using OFFSET.

The SQL query below says "return only 3 records, start on record 4 (OFFSET 3)":




ADD a WHERE CLAUSE

The following SQL statement selects the first three records from the "Customers" table, where the country is "Germany":