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

Drizzle ORM · Function

not

not inverts a Drizzle filter condition, allowing a query to select rows that do not satisfy the wrapped predicate. It is imported from drizzle-orm and commonly used inside .where().

How it works

not wraps a filter condition and reverses its result, producing a SQL NOT expression. Use it inside .where() to exclude rows matching a condition, such as users whose id equals a particular value.

Syntax

not(condition)

Parameters

NameTypeDescription
conditionSQL boolean expressionA Drizzle filter condition to invert.

Returns

A SQL boolean expression representing the negation of the supplied condition.

Key points

  • not is part of Drizzle ORM's built-in filter and conditional operator set.
  • Import not from the main drizzle-orm package.
  • The operator accepts a condition and keeps rows for which that condition is false.
  • Use not as the argument to a query's .where() method.
  • Drizzle emits SQL with NOT surrounding the wrapped predicate.

Common mistakes

  • The wrapped condition is negated, so rows satisfy the filter only when the original condition evaluates to false.

Example: Negate a filter condition

import { eq, not } from "drizzle-orm";

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

This selects users whose id is not 42.

When to use it

Negate an equality filter

Exclude records matching an equality predicate in a select query.

Invert a composed condition

Express the inverse of a compound filter when a direct comparison operator is insufficient.

Write a SQL negation expression

Build a custom SQL filter using the same negation concept through Drizzle's SQL expression support.

Interview questions

QWhat does Drizzle ORM's not operator do?

not negates a Drizzle filter condition and generates a SQL NOT expression around it. For example, not(eq(table.column, 5)) produces a condition equivalent to NOT (table.column = 5).

Follow-up: How would you negate a compound condition? Wrap the combined condition in not, using Drizzle's conjunction helpers before applying the negation.

QHow do you use not in a select query?

Import not from drizzle-orm and pass it an existing condition, such as eq(users.id, 42). The resulting expression can be supplied to .where() to filter query results.

Follow-up: What alternative is shown for writing the same SQL? Use the sql tagged template, for example sql\not ${users.id} = 42\.

QWhen would you choose not instead of a direct inequality operator?

The operator is useful when exclusion is expressed as the inverse of a positive predicate. not(eq(table.column, 5)) excludes rows where the column equals 5 and is rendered as NOT (table.column = 5).

Follow-up: When should a dedicated operator be preferred? Use operators such as ne when the intended comparison is directly inequality; use not when negating a broader condition.

  • eq
  • ne
  • notExists
  • and
  • or
  • sql

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