Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Drizzle ORM · Module

.limit

.limit() adds a SQL LIMIT clause and caps the rows returned by a query. Pair it with .offset() for pagination, and use a stable unique ordering for consistent pages.

How it works

The .limit() query-builder method adds a SQL LIMIT clause, restricting how many rows a query returns. Combine it with .offset() when skipping rows for pagination; the relational query API also accepts limit values for top-level and nested queries.

Syntax

.limit(count)

Parameters

NameTypeDescription
limitnumber | SQL placeholderMaximum number of rows to return; in relational-query configuration, this is supplied as limit.
offsetnumber | SQL placeholderNumber of rows to skip when used with pagination.

Returns

A query builder when chaining .limit(); executing the completed query returns rows constrained by the LIMIT clause.

Key points

  • Call .limit(count) on a select builder to add a SQL LIMIT clause.
  • The methods chain directly after .from(...), with .offset() optional.
  • A relational query can use a SQL placeholder when the limit must be supplied at execution time.

Example: Limit selected rows

const rows = await db.select().from(users).limit(10);

Returns at most 10 rows from users.

When to use it

Return only the first N rows

Restricting result size

Fetch a bounded page after skipping earlier rows

Page-number pagination

Cap records loaded for a related entity

Nested relational loading

Interview questions

QWhat does .limit() do in a Drizzle select query?

.limit() adds a LIMIT clause and caps the number of returned rows. For example, .select().from(users).limit(10) returns at most ten rows.

Follow-up: How would you paginate? Add .offset() for the number of rows to skip, and order by a unique column so page boundaries remain stable.

QHow are .limit() and .offset() used together?

Use .limit(pageSize).offset((page - 1) * pageSize) to implement page-number pagination. The limit is the page size, while the offset skips earlier rows.

Follow-up: What ordering rule matters? Order by a unique column, or include a unique column after a non-unique sort key.

QDoes Drizzle support limits in relational queries?

Relational queries expose limit in the findMany configuration, including nested relations. This lets a top-level query cap its rows and a relation cap its associated rows.

Follow-up: Can prepared relational queries parameterize the limit? Yes; use a SQL placeholder as the limit value and provide it when executing the prepared query.

  • offset
  • orderBy
  • findMany
  • $dynamic
  • sql.placeholder

Source: SQL Select. Checked 2026-10-16.