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

Drizzle ORM · Function

notBetween

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.

How it works

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.

Syntax

notBetween(column, from, to)

Parameters

NameTypeDescription
columnAny compatible Drizzle column or SQL expressionColumn or SQL expression whose value is tested.
fromValue compatible with the expressionLower boundary of the tested range.
toValue compatible with the expressionUpper boundary of the tested range.

Returns

A SQL predicate representing column NOT BETWEEN from AND to, suitable for use in where.

Key points

  • The function tests whether a column value lies outside the two supplied boundary values.
  • Import notBetween from the drizzle-orm package.
  • Use the returned predicate directly inside a query's where clause.
  • The generated SQL uses the NOT BETWEEN operator with the column and both bounds.

Example: Filter values outside a range

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.

When to use it

Exclude values within a numeric interval

Range exclusion

Find records outside a date window

Date filtering

Combine an outside-range predicate with other filters

Query composition

Interview questions

QWhat does 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(...).

QWhat arguments does 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.

QWhere is the result of 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.

  • between
  • eq
  • gt
  • gte
  • lt
  • lte
  • and
  • or

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