Skip to main content
Drizzle ORM provides a powerful and type-safe query builder for selecting data from your database. The select query builder supports a wide range of operations including filtering, joining, grouping, and ordering.

Basic Select

Select all columns from a table:

Partial Select

Select specific columns from a table:

Filtering with Where

Use the where() method to filter results:

Ordering Results

Use orderBy() to sort query results:

Limiting and Offsetting

Control the number of results returned:

Distinct

Select only distinct values:

Group By

Group results by one or more columns:

Having Clause

Filter grouped results:

Set Operations

Combine multiple select queries:

Conditional Where

Build dynamic queries with conditional logic:

With Clause (CTE)

Use Common Table Expressions:

For Update (PostgreSQL)

Lock rows for update:

Conditional Operators Reference

Comparison

  • eq() - Equal to
  • ne() - Not equal to
  • gt() - Greater than
  • gte() - Greater than or equal
  • lt() - Less than
  • lte() - Less than or equal

Logical

  • and() - Combine with AND
  • or() - Combine with OR
  • not() - Negate condition

Patterns

  • like() - Pattern matching
  • ilike() - Case-insensitive pattern
  • notLike() - Not matching pattern
  • notIlike() - Case-insensitive not matching

Ranges & Sets

  • between() - Between two values
  • notBetween() - Not between values
  • inArray() - In array of values
  • notInArray() - Not in array

Null Checks

  • isNull() - Is NULL
  • isNotNull() - Is NOT NULL

Subqueries

  • exists() - Subquery has results
  • notExists() - Subquery has no results

Type Safety

Drizzle ensures complete type safety:
All query methods are fully typed, providing autocomplete and compile-time type checking.

Next Steps

Joins

Learn about joining tables together

Aggregations

Use aggregate functions like count, sum, avg

Subqueries

Write complex nested queries

Insert

Insert data into tables