Ordering, Limit & Offset in Drizzle ORM

From the Drizzle ORM cheat sheet · Select Queries · verified Jul 2026

Ordering, Limit & Offset

Sort results and implement pagination with limit/offset.

typescript
import { asc, desc } from 'drizzle-orm';

// Order by single column
await db.select().from(users)
  .orderBy(asc(users.name));

// Order by multiple columns
await db.select().from(users)
  .orderBy(desc(users.createdAt), asc(users.name));

// Pagination with limit and offset
const page = 2;
const pageSize = 20;
await db.select().from(users)
  .orderBy(desc(users.createdAt))
  .limit(pageSize)
  .offset((page - 1) * pageSize);
💡 asc/desc imported from 'drizzle-orm'
⚡ Pass multiple columns for multi-level sorting
📌 Always use orderBy with limit for consistency
🟢 Cursor-based pagination is better at scale
selectorderpaginationlimit

More Drizzle ORM tasks

Back to the full Drizzle ORM cheat sheet