© 2026 Hedgehog Software, LLC

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

orderBy related table column

Given a relational query such as

const matchResult = await db.query.matches.findMany({
        where: and(
          between(matches.time, from, to),
        ),
        orderBy: [
          asc(matches.time),
        ],
        with: {
          team1: true, // one to one with a "team" entity
          team2: true, // one to one with a "team" entity
        },
      });
const matchResult = await db.query.matches.findMany({
        where: and(
          between(matches.time, from, to),
        ),
        orderBy: [
          asc(matches.time),
        ],
        with: {
          team1: true, // one to one with a "team" entity
          team2: true, // one to one with a "team" entity
        },
      });


how can I additionally order by a column from the
team1
team1
relation? (bear in mind that a
limit
limit
and
offset
offset
may be used, so I don't want to have to fetch all results then sort them after, as it defeats the point of using mysql for this task)
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

orderBy with variable column
Drizzle TeamDTDrizzle Team / help
3y ago
How to filter by a column in a related table?
Drizzle TeamDTDrizzle Team / help
3y ago
Dynamic orderBy
Drizzle TeamDTDrizzle Team / help
3y ago
Query a table based on related table
Drizzle TeamDTDrizzle Team / help
3y ago