---
title: Select Basics
description: Build typed select queries with from, where, order, limit, and select.
---

# Select Basics

Start every query with `db.from(...)`.

```ts
const query = db
	.from("users")
	.where(({ users }) => users.id.gt(10, db.dialect))
	.orderBy(({ users }) => users.createdAt.desc())
	.limit(20)
	.offset(40)
	.select(({ users }) => ({
		id: users.id,
		email: users.email,
	}));
```

Execute or inspect:

```ts
const rows = await query.execute();
const compiled = query.compile();
```

## Core methods

- `from(source)`
- `where(predicate)`
- `orderBy(predicate)`
- `limit(number)`
- `offset(number)`
- `select(projection)`

## Repeated `where`

Multiple `.where(...)` calls are combined with SQL `and`.

```ts
db
	.from("users")
	.where(({ users }) => users.id.gt(10, db.dialect))
	.where(({ users }) => users.email.like("%@example.com", db.dialect));
```

## Typed source object

`from("users")` gives a projection callback object with one key (`users`).
Each column is an `Expr<...>` with the correct inferred type.

<!--
Sitemap

URL: https://tsql-docs.pages.dev/v0.5.0/guides/quickstart.md
Title: Quickstart
Description: Define migrations, run them safely, and write typed SQL in application code.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/connecting.md
Title: Connecting
Description: Create a database instance from schema, dialect, and runtime connection.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/dialect-and-compilation.md
Title: Dialect & SQL Compilation
Description: Configure SQL dialect behavior and compile schema/query SQL.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/grouping-and-aggregates.md
Title: Grouping & Aggregates
Description: Use groupBy, having, and aggregate helpers for analytical queries.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/joins-and-aliases.md
Title: Joins & Aliases
Description: Join tables, use left joins, and self-join safely with aliases.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/migration-runtime.md
Title: Migration Runtime
Description: Understand db.migrate behavior, tracking, and failure semantics.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/mutations.md
Title: Mutations
Description: Insert, update, and delete data with compile or execute.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/predicates-and-expressions.md
Title: Predicates & Expressions
Description: Use Expr methods, logical operators, null checks, and expression composition.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/raw-sql.md
Title: Raw SQL
Description: Use raw templates and expression templates when fluent APIs are not enough.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/schema-and-migrations.md
Title: Schema & Migrations
Description: Define tables, columns, and indexes with ordered migration history.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/select-basics.md
Title: Select Basics
Description: Build typed select queries with from, where, order, limit, and select.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/transactions.md
Title: Transactions
Description: Use explicit begin, commit, rollback, and await using for safety.

URL: https://tsql-docs.pages.dev/v0.5.0/reference/type-utilities.md
Title: Type Utilities
Description: Derive row, insert, and update types directly from schema.
-->
