LIMIT
Contents
Use the LIMIT
clause to restrict the number of returned rows. When you use a single
integer n with LIMIT
, the first n rows will be returned. Use the ORDER BY
clause to control which rows come first. You can also select a number of rows after an offset
using either of the following:
LIMIT offset, row_count LIMIT row_count OFFSET offset
When you provide an offset m with a limit n, the first m rows will be ignored, and the following n rows will be returned.
Executing an UPDATE with the LIMIT
clause are not safe for replication.
MariaDB starting with 10.0.11
Since MariaDB 10.0.11, LIMIT 0
has been an exception to this rule (see MDEV-6170).
MariaDB starting with 5.5.21
Beginning in MariaDB 5.5.21, there is a LIMIT ROWS EXAMINED
optimization which provides the
means to terminate the execution of SELECT statements which examine too
many rows, and thus use too many resources. See the LIMIT ROWS EXAMINED
page for details.
Examples
CREATE TABLE members (name VARCHAR(20)); INSERT INTO members VALUES('Jagdish'),('Kenny'),('Rokurou'),('Immaculada'); SELECT * FROM members; +------------+ | name | +------------+ | Jagdish | | Kenny | | Rokurou | | Immaculada | +------------+ SELECT * FROM members LIMIT 2; +---------+ | name | +---------+ | Jagdish | | Kenny | +---------+ SELECT * FROM members ORDER BY name; +------------+ | name | +------------+ | Immaculada | | Jagdish | | Kenny | | Rokurou | +------------+ SELECT * FROM members ORDER BY name LIMIT 2; +------------+ | name | +------------+ | Immaculada | | Jagdish | +------------+ SELECT * FROM members ORDER BY name LIMIT 3,1; +---------+ | name | +---------+ | Rokurou | +---------+