ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Teamโ€ข14mo agoโ€ข
10 replies
Anthony

How to filter by joined tables with Drizzle query syntax?

Hi there! I was wondering if there was a way to query by a joined table using drizzle query syntax. Here's a concise example:

TABLE users
id
name

TABLE info
id
user_id
organization_id
description

users.id <-> info.user_id (one-to-one)
TABLE users
id
name

TABLE info
id
user_id
organization_id
description

users.id <-> info.user_id (one-to-one)


import { posts } from './schema';

const results = await db.users.findMany({
  with: {
    info: true;
  },
  where: (users, { eq }) => {
    return [eq(info.organizationId, '0')];
  }
});

console.log(results);

// error: PostgresError: column users.organization_id does not exist
import { posts } from './schema';

const results = await db.users.findMany({
  with: {
    info: true;
  },
  where: (users, { eq }) => {
    return [eq(info.organizationId, '0')];
  }
});

console.log(results);

// error: PostgresError: column users.organization_id does not exist


So how is this supposed to be done? users <-> info is 1 to 1 so with
.select()
.select()
query I would just filter by the joined table like I'm trying above, but this is not working in this case. I can't add a where to the info block since it's a one to one.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Filter on joined (with) tables
Drizzle TeamDTDrizzle Team / help
2y ago
Order by on Joined Tables
Drizzle TeamDTDrizzle Team / help
12mo ago
Using Query Syntax to filter by FK's field
Drizzle TeamDTDrizzle Team / help
3y ago
How can I filter on a joined table field (nested value) with the relational query syntax?
Drizzle TeamDTDrizzle Team / help
3y ago