LIMIT Clause

The LIMIT clause is used to specify the maximum number M of results to return to the application. M is computed by an expression that may be a single integer literal, or a single external variable, or any expression which is built from literals and external variables and returns a single non-negative integer.

Syntax

limit_clause ::= LIMIT add_expression

For definition of the syntax component referenced in this statement, see:

Semantics

Although it’s possible to use limit without an order-by clause, it does not make much sense to do so. This is because without an order-by, results are returned in a random order, so the subset of results returned will be different each time the query is run.

Example 1 - LIMIT Clause

SELECT * FROM users
WHERE age > 30
ORDER BY age
LIMIT 5