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

Drizzle ORM · Function

lt

lt creates a strict less-than filter condition in Drizzle ORM. Use it in where clauses to select rows whose column value is below a supplied value.

How it works

Import lt from drizzle-orm and pass a column plus a comparison value. It creates a less-than condition that can be supplied to a query's where clause, including relational query filters.

Syntax

lt(column, value)

Parameters

NameTypeDescription
columnColumn or SQL expressionThe table column or SQL expression to compare.
valueComparable valueThe comparison value, represented as n in the documentation.

Returns

A SQL filter condition representing a strict less-than comparison.

Key points

  • Drizzle provides filter operators across its supported SQL dialects.
  • The operator is imported from the main drizzle-orm package.
  • lt matches values strictly below the comparison value.

Common mistakes

  • The comparison is strict: rows equal to the supplied value do not match.

Example: Filter by a value less than a column value

import { lt } from 'drizzle-orm';
import { users } from './schema';

const olderUsers = await db
  .select()
  .from(users)
  .where(lt(users.createdAt, new Date('2024-01-01')));

Selects users whose creation timestamp is earlier than the supplied date.

When to use it

Threshold filtering

Filtering records by a threshold such as a timestamp, number, or other comparable column value.

Cursor pagination

Selecting the preceding page when implementing descending cursor-based pagination.

Nested relation filtering

Restricting nested relational records through a relational query where callback.

Interview questions

QWhat does lt do?

lt is Drizzle's less-than filter operator. It receives a column and a value, then produces a condition suitable for a query's where clause.

Follow-up: How would you express the opposite comparison? Use gt when the column value must be greater than the supplied value.

QHow is lt used in a query?

Import it from drizzle-orm, then call lt(table.column, value) inside .where(...). The result can be combined with other filter operators when building a query.

Follow-up: How can it be used for descending cursor pagination? Use lt to select rows whose cursor is below the current cursor, together with descending ordering.

QWhat is a practical use for lt?

The operator compares a selected column against the provided value and matches values below it. The documentation also shows it in relational query filters for nested records.

Follow-up: What should the cursor property be for reliable cursor comparison? The documentation recommends that a cursor be unique and sequential.

  • gt
  • lte
  • eq
  • asc
  • desc
  • where

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