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

Drizzle ORM · Module

.from

.from() sets the table or query source for a Drizzle select statement. It works with projections, filters, joins, ordering, pagination, subqueries, and prepared statements while preserving type-safe results.

How it works

.from() identifies the table or query source for a Drizzle select statement. It composes with selections, joins, filters, ordering, pagination, subqueries, and prepared statements while preserving inferred result types.

Syntax

db.select(selection?).from(source)

Parameters

NameTypeDescription
sourcetable or aliased subqueryThe table or aliased subquery that supplies rows to the select builder.

Returns

A composable select query builder whose executed result contains rows inferred from the selected source and projection.

Key points

  • The basic form is db.select().from(table), which retrieves rows from the supplied table.
  • Use a selection object with .select() when the query should return a chosen subset or renamed projection of the source columns.
  • Attach .where() after .from() to restrict returned rows with Drizzle filter operators.
  • Add .limit() and .offset() after the source and ordering clauses to implement paginated reads.
  • A subquery can serve as a derived source, enabling nested query composition through .from().

Common mistakes

  • Do not assume .from() alone changes the column-selection rule: Drizzle's select builder explicitly lists columns rather than emitting select *.
  • When using the documented pagination example, .orderBy() is required before .limit() to make the result ordering explicit.

Example: Select rows from a table

import { drizzle } from 'drizzle-orm/node-postgres';
import { eq } from 'drizzle-orm';
import { users } from './schema';

const db = drizzle(process.env.DATABASE_URL!);
const result = await db
  .select()
  .from(users)
  .where(eq(users.id, 42));

console.log(result);

Builds and executes a type-safe select query whose source table is users and whose rows match the specified condition.

When to use it

Basic table selection

Read complete rows from a schema table.

Projected filtered query

Return only selected fields and restrict records with predicates.

Subquery composition

Use a derived query as the source for an outer select.

Pagination

Fetch a bounded window of ordered records.

Interview questions

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

.from() supplies the source table for a select query, such as db.select().from(users). The builder can then add conditions, joins, ordering, and pagination while retaining type-safe results.

Follow-up: How can a derived source be used? Build a subquery, give it an alias with .as(), and pass that aliased query to .from().

QHow do filtering and projection combine with .from()?

A select query can use .from() with a table and compose a filter through .where(), for example .from(users).where(eq(users.id, 42)). The selected fields remain inferred from the schema or selection object.

Follow-up: How would you return only chosen fields? Pass a selection object to .select(), mapping output names to table columns before calling .from().

QCan .from() use a subquery instead of a table?

.from() can receive a subquery source, allowing one query to be embedded in another. The subquery should be aliased so its fields can be referenced by the outer query.

Follow-up: How can repeated executions avoid rebuilding SQL? Prepare the composed query with .prepare(name) and execute it with placeholder values.

  • select()
  • selectDistinct()
  • where()
  • orderBy()
  • limit()
  • offset()
  • leftJoin()
  • prepare()

Source: Drizzle ORM - Select. Checked 2026-10-16.