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

Drizzle ORM · Module

.innerJoin

innerJoin combines rows from two Drizzle tables when a supplied SQL condition matches. It produces SQL INNER JOIN semantics and type-inferred, nested results keyed by the participating tables.

How it works

Call innerJoin on a select query with the table to join and an equality or other SQL condition. Drizzle emits an SQL INNER JOIN, returning rows only when the condition matches; the result is grouped under the participating table names and is inferred with TypeScript types.

Syntax

db.select().from(table).innerJoin(joinedTable, on)

Parameters

NameTypeDescription
tableTable or selectableThe table or selectable source to join to the current query.
onSQL conditionThe SQL expression that determines which rows match.

Returns

A promise resolving to an array of objects containing the matching rows from the joined tables, with inferred TypeScript types.

Key points

  • A join combines tables through related columns; innerJoin applies this concept to a typed Drizzle select query.
  • The API keeps SQL-like join syntax while preserving compile-time type information for selected rows.
  • Use innerJoin after from, passing the table to join and a condition such as matching a primary key to a foreign key.
  • The method generates an INNER JOIN with an ON predicate connecting the columns.
  • The inferred result is an array whose entries contain separate nested properties for the joined tables.
  • The joins documentation places inner joins alongside full, left, right, cross, and lateral join APIs.

Common mistakes

  • Do not assume innerJoin is the only join form; the joins API also exposes lateral and other join variants.

Example: Match users with their pets

import { eq } from 'drizzle-orm';
import { users, pets } from './schema';

const result = await db
  .select()
  .from(users)
  .innerJoin(pets, eq(users.id, pets.ownerId));

This query returns users only when their IDs match a pet's ownerId, and includes both table-shaped results.

When to use it

Load only parents with matching children

Retrieve related records

Return columns from two related tables

Combine normalized data

Keep join results type-safe

Use typed SQL joins

Interview questions

QWhat does innerJoin do in Drizzle ORM?

innerJoin combines two tables using a supplied SQL condition, such as eq(users.id, pets.ownerId). Because it is an SQL INNER JOIN, only matching rows are returned, and Drizzle infers a result object containing both table fields.

Follow-up: How would you preserve users without pets? Use leftJoin instead, accepting that the joined table's result can be null.

QWhat arguments does innerJoin take?

The first argument after from is the table being joined, and the second is the join condition. A typical call is db.select().from(users).innerJoin(pets, eq(users.id, pets.ownerId)).

Follow-up: How can the selected shape be narrowed? Pass an object to select, such as select({ user: users, pet: pets }), rather than selecting every column.

QWhat SQL and result shape does innerJoin produce?

Drizzle translates the method call into SQL resembling select ... from users inner join pets on users.id = pets.owner_id. The returned rows are represented as nested objects keyed by the participating tables.

Follow-up: What is the lateral counterpart? Build and alias a subquery, then call innerJoinLateral(subquery, sqltrue).

  • innerJoinLateral
  • leftJoin
  • rightJoin
  • fullJoin
  • crossJoin
  • eq

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