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

Drizzle ORM · Function

ne

ne creates a type-safe inequality condition for Drizzle ORM queries. It matches rows where the first operand is not equal to the second and generates SQL with <>.

How it works

The ne operator builds a type-safe inequality predicate for a query. It compares a column with a value or another column and produces SQL using the <> operator.

Syntax

ne(column, value)

Parameters

NameTypeDescription
columnColumn or SQL expressionColumn or SQL expression whose value is tested for inequality.
nValue or ColumnValue or column compared against the first operand.

Returns

A SQL predicate representing inequality, suitable for use in a query's where clause.

Key points

  • Use ne when a row should match only if the compared value differs from the supplied operand.
  • Import the operator directly from the main drizzle-orm package.
  • Place the predicate in a query builder's where clause to filter selected rows.
  • The generated SQL uses the standard SQL <> inequality operator.
  • The right-hand operand may be another column, enabling column-to-column inequality checks.

Example: Filter with ne

import { ne } from "drizzle-orm";
import { users } from "./schema";

const result = await db
  .select()
  .from(users)
  .where(ne(users.id, 5));

Selects users whose id is not 5.

When to use it

Filter out a value

Exclude rows matching a specific identifier or other literal value.

Compare columns

Find rows where two stored columns differ.

Build conditional queries

Compose an inequality predicate with Drizzle query-builder filters.

Interview questions

QWhat does Drizzle ORM’s ne operator do?

ne creates a predicate that matches rows where a value is not equal to the supplied value. For example, ne(table.column, 5) generates a condition equivalent to table.column <> 5.

Follow-up: How can two columns be compared? Use the second column as the right-hand operand, such as ne(table.column1, table.column2), which generates a column-to-column <> comparison.

QHow do you use ne in a query?

Import ne from drizzle-orm, then pass the target column and comparison value to it inside where. The resulting predicate can be used with Drizzle’s select query builder.

Follow-up: What SQL does the predicate represent? It represents an inequality condition using SQL’s <> operator.

QCan ne compare two columns?

The operator supports comparing one table column with another, not only comparing a column to a literal. Passing two columns produces a condition that checks whether their values differ.

Follow-up: Why is this useful? It lets a query express row-level comparisons directly in SQL without manually writing a raw condition.

  • eq
  • gt
  • gte
  • lt
  • lte
  • inArray
  • not

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