Value-based filtering
Restrict a select, update, or delete query to rows matching a supplied value.
Drizzle ORM · Function
eq creates an equality filter for a value or another column. Use it in query conditions such as where and joins.
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.
eq(left, right)| Name | Type | Description |
|---|---|---|
left | SQL expression | Column or SQL expression on the left side of the equality comparison. |
right | value or SQL expression | Value or column/SQL expression compared with the first operand. |
An SQL condition representing equality between the two operands.
eq represents the equality comparison between its first expression and the supplied second operand.eq from the main drizzle-orm package alongside the other filter and conditional operators.where clause to retain a concise, type-safe filter expression.eq are parameterized automatically, so do not construct SQL by interpolating them yourself.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.
Restrict a select, update, or delete query to rows matching a supplied value.
Join related tables by requiring two key columns to match.
Find rows where two columns or SQL expressions have equal results.
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.
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)).
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.
negtgteltlteandorsql