© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
2 replies
jakeleventhal

Subquery/join in relational query

are the following queries identical?
await db.query.posts.findFirst({
  where: and(
    eq(posts.type, 'blog'),
    inArray(
      posts.userId,
      db
        .select({ id: users.id })
        .from(users)
        .where(and(eq(users.id, userId), isNotNull(users.email)))
    )
  )
});
await db.query.posts.findFirst({
  where: and(
    eq(posts.type, 'blog'),
    inArray(
      posts.userId,
      db
        .select({ id: users.id })
        .from(users)
        .where(and(eq(users.id, userId), isNotNull(users.email)))
    )
  )
});

await db.query.posts.findFirst({
  with: { user: true },
  where: and(
    eq(posts.type, 'blog'),
    isNotNull(users.email)
  )
});
await db.query.posts.findFirst({
  with: { user: true },
  where: and(
    eq(posts.type, 'blog'),
    isNotNull(users.email)
  )
});
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

Relational query builder in mysql?
Drizzle TeamDTDrizzle Team / help
3y ago
Simple relational query in sqlite
Drizzle TeamDTDrizzle Team / help
3y ago
Nullable relational query?
Drizzle TeamDTDrizzle Team / help
3y ago