© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•11mo ago•
4 replies
Dr Use

Complex filter on query.

Hello everyone, here's the query :

db.query.ordersTable.findMany({
      with: {
        products: true,
        user: {
          columns: {
            password: false,
          },
        },
      },
      where: and(
        eq(ordersTable.draft, false),
        or(
          query === "" ? sql`TRUE` : undefined,
          eq(ordersTable.id, Number(query) || 0),
          ilike(sql`productsOrderTable.name`, `%${query}%`),
        ),
      ),
  )
db.query.ordersTable.findMany({
      with: {
        products: true,
        user: {
          columns: {
            password: false,
          },
        },
      },
      where: and(
        eq(ordersTable.draft, false),
        or(
          query === "" ? sql`TRUE` : undefined,
          eq(ordersTable.id, Number(query) || 0),
          ilike(sql`productsOrderTable.name`, `%${query}%`),
        ),
      ),
  )


I get the error : missing FROM-clause entry for table "productsordertable"

I can't find a way to filter the orders according to the user or the products.
For exemple I want the orders where the user name is "john".
Or I want the orders where some of the products name contains "foo".

PS : productsOrderTable has a column order_id as a foreign key

I can only filter according to the ordersTable direct columns
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

Build a complex query
Drizzle TeamDTDrizzle Team / help
14mo ago
Filter based querying
Drizzle TeamDTDrizzle Team / help
2y ago
How to filter query based on children table?
Drizzle TeamDTDrizzle Team / help
3y ago
`where` within `where`? confused about complex query
Drizzle TeamDTDrizzle Team / help
3y ago