© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•12mo ago•
27 replies
jkb

Order by on Joined Tables

I am attempting to do an order by for a joined table

export const playerItem = pgTable(
  "playerItem",
  {
    id: uuid()
      .primaryKey()
      .default(sql`gen_random_uuid()`),
    playerId: uuid().references(() => player.id),
    ...defaultColumns,
  },
  (t) => [index("player_item_pk_index").on(t.id)],
)
export const player = pgTable(
  "player",
  {
    id: uuid()
      .primaryKey()
      .default(sql`gen_random_uuid()`),
    fullName: text().notNull(),
    firstName: text().notNull(),
    lastName: text().notNull(),

    ...defaultColumns,
  },
  (t) => [index("player_pk_index").on(t.id)],
)
export const playerItem = pgTable(
  "playerItem",
  {
    id: uuid()
      .primaryKey()
      .default(sql`gen_random_uuid()`),
    playerId: uuid().references(() => player.id),
    ...defaultColumns,
  },
  (t) => [index("player_item_pk_index").on(t.id)],
)
export const player = pgTable(
  "player",
  {
    id: uuid()
      .primaryKey()
      .default(sql`gen_random_uuid()`),
    fullName: text().notNull(),
    firstName: text().notNull(),
    lastName: text().notNull(),

    ...defaultColumns,
  },
  (t) => [index("player_pk_index").on(t.id)],
)


I want to query
playerItem
playerItem
with an order by on
player.lastName
player.lastName
descending. I don't see any examples in the documentation on how to do this or if Drizzle allows it.

This is a simplified example of the schema, denormalizing would make sense here, but I purposely excluded the rest of the columns/relations to make reading easier

Any help would be appreciated!
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
How to filter by joined tables with Drizzle query syntax?
Drizzle TeamDTDrizzle Team / help
14mo ago
"Extend" tables by other tables
Drizzle TeamDTDrizzle Team / help
3y ago
Order By Relational Data
Drizzle TeamDTDrizzle Team / help
10mo ago