Exclude values within a numeric interval
Range exclusion
Drizzle ORM · Function
notBetween builds a Drizzle filter for values outside a two-bound range. Use it in a query’s where clause to generate SQL with NOT BETWEEN.
notBetween creates a SQL NOT BETWEEN condition for a column and two boundary values. Pass the resulting expression to a query's where clause to keep rows whose column value is outside that range.
notBetween(column, from, to)| Name | Type | Description |
|---|---|---|
column | Any compatible Drizzle column or SQL expression | Column or SQL expression whose value is tested. |
from | Value compatible with the expression | Lower boundary of the tested range. |
to | Value compatible with the expression | Upper boundary of the tested range. |
A SQL predicate representing column NOT BETWEEN from AND to, suitable for use in where.
notBetween from the drizzle-orm package.where clause.NOT BETWEEN operator with the column and both bounds.import { notBetween } from "drizzle-orm";
import { users } from "./schema";
const results = await db
.select()
.from(users)
.where(notBetween(users.age, 18, 65));Selects users whose age falls outside the inclusive range from 18 through 65.
Range exclusion
Date filtering
Query composition
notBetween do?notBetween is a Drizzle filter imported from drizzle-orm. It accepts a column and two values, then produces a condition equivalent to SQL column NOT BETWEEN lower AND upper.
Follow-up: How would you use it in a query? Import it and pass notBetween(table.column, lower, upper) to .where(...).
notBetween take?The documented signature is notBetween(table.column, 2, 7). It generates a predicate that excludes values in the specified two-value range.
Follow-up: What SQL form does Drizzle generate? It emits NOT BETWEEN, as in WHERE "table"."column" NOT BETWEEN 2 AND 7.
notBetween used?Use it with Drizzle's SQL-like query API by placing the returned condition in .where(...). The page demonstrates this with db.select().from(table).where(...).
Follow-up: How can the condition be adapted to another table? Replace the example table and column references while keeping the same three-argument function shape.
betweeneqgtgteltlteandor