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

Drizzle ORM · Function

eq

eq creates an equality filter for a value or another column. Use it in query conditions such as where and joins.

How it works

eq builds an equality condition for a column or SQL expression and a value or another column. Pass the resulting condition to query methods such as where or join methods such as leftJoin; Drizzle translates it to SQL equality syntax and parameterizes supplied values.

Syntax

eq(left, right)

Parameters

NameTypeDescription
leftSQL expressionColumn or SQL expression on the left side of the equality comparison.
rightvalue or SQL expressionValue or column/SQL expression compared with the first operand.

Returns

An SQL condition representing equality between the two operands.

Key points

  • eq represents the equality comparison between its first expression and the supplied second operand.
  • Import eq from the main drizzle-orm package alongside the other filter and conditional operators.
  • Use the predicate directly inside a query's where clause to retain a concise, type-safe filter expression.
  • For a literal comparison, Drizzle generates SQL using the equality operator between the qualified column and the value.
  • The second operand may be another column expression, enabling column-to-column equality checks.
  • Column comparisons compile to SQL that places both qualified columns around the equality operator.

Common mistakes

  • Values passed to eq are parameterized automatically, so do not construct SQL by interpolating them yourself.

Example: Filter rows with equality

import { eq } from "drizzle-orm";
import { users } from "./schema";

const result = await db
  .select()
  .from(users)
  .where(eq(users.id, 42));

Selects the user whose id equals 42.

When to use it

Value-based filtering

Restrict a select, update, or delete query to rows matching a supplied value.

Join predicates

Join related tables by requiring two key columns to match.

Expression comparison

Find rows where two columns or SQL expressions have equal results.

Interview questions

QWhat does eq do?

eq creates an equality predicate. For example, eq(table.column, 5) becomes a condition equivalent to table.column = 5, and it can be supplied to where.

Follow-up: How can it compare columns instead of a literal? Pass the second column expression, such as eq(table.column1, table.column2); Drizzle emits column-to-column equality.

QHow is eq commonly used in a select query?

Import eq from drizzle-orm and pass it to a query condition method. A typical usage is .where(eq(users.id, 42)).

Follow-up: Can it be used in joins? Yes. The documentation demonstrates it as the join condition in .leftJoin(users, eq(posts.ownerId, users.id)).

QCan eq compare two columns?

The operator supports comparing a table column with another table column, not only with a literal. The documentation shows eq(table.column1, table.column2) producing equality between those two columns.

Follow-up: What SQL shape does a literal comparison produce? It produces a parameterized equality predicate, such as users.id = $1, with the value supplied separately.

  • ne
  • gt
  • gte
  • lt
  • lte
  • and
  • or
  • sql

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