Querying with Relations in Drizzle ORM

From the Drizzle ORM cheat sheet · Relations · verified Jul 2026

Querying with Relations

Use the relational query builder to fetch nested data.

typescript
// Fetch users with their posts
const usersWithPosts = await db.query.users.findMany({
  with: {
    posts: true,
  },
});
💡 db.query.* requires schema passed to drizzle()
⚡ Many-to-many nests through the junction table
📌 Use columns: {} to select specific fields
🟢 findFirst returns single record or undefined
relationsquerywith

Continue with Drizzle ORM

Save the full cheat sheet or work through every related task.

More Drizzle ORM tasks

Back to the full Drizzle ORM cheat sheet