Filter out listed values
Exclude rows with known identifiers, statuses, or other values held in an application array.
Drizzle ORM · Function
notInArray filters rows whose column value is not among a supplied array or the results of a subquery. It produces a SQL NOT IN condition.
Use notInArray to create a filter that keeps rows whose column value is absent from an array or from the results of a subquery. Drizzle translates it to SQL using the NOT IN operator.
notInArray(column, values)| Name | Type | Description |
|---|---|---|
column | Column | The table column whose value is tested. |
values | array | SQL query | An array of comparison values or a query selecting comparison values. |
A SQL condition expression for use in a query filter.
import { notInArray } from "drizzle-orm";
const result = await db
.select()
.from(users)
.where(notInArray(users.id, [1, 2, 3]));Selects users whose id is not among the specified values.
Exclude rows with known identifiers, statuses, or other values held in an application array.
Exclude rows whose column matches values selected from another table.
notInArray builds a condition stating that a column does not match any value in the supplied array. For example, it generates a SQL NOT IN predicate.
Follow-up: How can the comparison set come from the database? Pass a select query instead of a literal array; Drizzle emits NOT IN with a subquery.
Import notInArray from drizzle-orm and pass the table column followed by an array of values. Use the resulting expression in where() to exclude those values.
Follow-up: What SQL shape does the array form produce? It becomes a NOT IN list containing the supplied values.
The second argument can be a query selecting one column, not only an array. This lets the filter exclude rows whose value appears in another query's result.
Follow-up: What is the generated SQL shape for that form? The predicate uses NOT IN followed by a scalar subquery.
inArrayeqnotandor