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

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 6-20 LIMIT Clause

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