© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
138 replies
AndréLB

Joins with results in arrays

      const fetchedOrderServices = await tx
        .select()
        .from(orderServices)
        .where(eq(orderServices.orderID, order))

      const fetchedOrderLocalServices = await tx
        .select()
        .from(orderLocalServices)
        .where(eq(orderLocalServices.orderID, order))

      const [fetchedOrder] = await tx
        .select()
        .from(orders)
        .where(eq(orders.orderID, order))
        .leftJoin(rentCarBookings, eq(rentCarBookings.orderID, order))
      const fetchedOrderServices = await tx
        .select()
        .from(orderServices)
        .where(eq(orderServices.orderID, order))

      const fetchedOrderLocalServices = await tx
        .select()
        .from(orderLocalServices)
        .where(eq(orderLocalServices.orderID, order))

      const [fetchedOrder] = await tx
        .select()
        .from(orders)
        .where(eq(orders.orderID, order))
        .leftJoin(rentCarBookings, eq(rentCarBookings.orderID, order))


I would like a single select with joins that gives me more or less the same result. Something along the lines of:
{
fetchedOrder: {
  orderID: OrderID,
  customerID: CustomerID
},
localServices: {orderID: OrderID, localServiceID: LocalServiceID}[},
globalServices: {orderID: OrderID, globalServiceID: GlobalServiceID}[]
}
{
fetchedOrder: {
  orderID: OrderID,
  customerID: CustomerID
},
localServices: {orderID: OrderID, localServiceID: LocalServiceID}[},
globalServices: {orderID: OrderID, globalServiceID: GlobalServiceID}[]
}
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
Next page

Similar Threads

Many-to-Many joins results in weird values
Drizzle TeamDTDrizzle Team / help
3y ago
How to flatten select results from query with left joins (one-to-many)?
Drizzle TeamDTDrizzle Team / help
3y ago
Joins with the Query API
Drizzle TeamDTDrizzle Team / help
2y ago
What's the recommended way to handle joins that aggregate results?
Drizzle TeamDTDrizzle Team / help
15mo ago