Meaning
The LIMIT clause restricts the number of rows returned by a SELECT statement. It helps control result size, which is useful for pagination and preventing excessive data transfer. Use it when you need only a subset of rows from a larger result set.
Primary Function
Query limitation
Communicative Purpose
Limits the number of rows returned by a query.
Pattern
LIMIT limit_count
Core Structure
LIMIT ...
Função primária
Query limitation
Propósito comunicativo
Limits the number of rows returned by a query.
Situações de gatilho
Web application: displaying the first page of search results; Data analysis: exporting a sample of rows from a large table; API endpoint: returning a limited number of records to avoid overloading the client
Contextos
SQL databases (PostgreSQL, MySQL, SQLite) and ORM query builders that generate SQL.
Padrão
LIMIT limit_count
Estrutura central
LIMIT ...
Slots de substituição
limit_count: integer (non-negative)
Colocados típicos
- SELECT
- FROM
- WHERE
- ORDER BY
Substituições comuns
- FETCH FIRST n ROWS ONLY (ANSI)
- TOP n (SQL Server)
- LIMIT n OFFSET m
Erros comuns
Using LIMIT without ORDER BY leading to nondeterministic results; forgetting to add OFFSET for pagination; using negative limits.
Similar / contraste
OFFSET m (skip rows), FETCH FIRST, TOP, keyset pagination
Interferências
Coming from Python list slicing: assuming LIMIT works like slicing with start:stop; LIMIT only limits count unless combined with OFFSET.
Família do chunk
- OFFSET
- FETCH
- TOP
- keyset pagination
Nuance
Without ORDER BY, the subset of rows is arbitrary; LIMIT can allow early termination and improve query performance.
Efeito pragmático
Ensures predictable result set size, improves performance, and enables pagination.
Dica de memória
Think LIMIT as a bouncer: only let N rows through the door.
Nota
Without an ORDER BY clause, the rows returned by LIMIT are nondeterministic, which can lead to inconsistent pagination results.
Upgrade path
Use LIMIT with OFFSET for pagination, or adopt keyset pagination for better performance on large datasets.
Log in to save chunks.