Ā© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•17mo ago•
3 replies
Kiwibe

How to `as` a table name

Hey šŸ‘‹ ,

I have a parent query that use a table let's say A, and in this parent query it contains another query which will also use A, how in drizzle can I as the table name for the sub query ?

The code would roughtly look like so:
const childQ = db.select({
    id: A.id --> need to joined A
}).from(B).leftJoin(A, eq(B.childrenIDs, A.id --> need to use joined A)).where(eq(B.id, A.id --> need to use A from parent ))

db.select({
    parentId: A.id,
    childIds: 
}).from(A).leftJoin(B, eq(A.id, B.id))
const childQ = db.select({
    id: A.id --> need to joined A
}).from(B).leftJoin(A, eq(B.childrenIDs, A.id --> need to use joined A)).where(eq(B.id, A.id --> need to use A from parent ))

db.select({
    parentId: A.id,
    childIds: 
}).from(A).leftJoin(B, eq(A.id, B.id))

šŸ™
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

How to create a variable with the same name as the table name?
Drizzle TeamDTDrizzle Team / help
3y ago
reference table name as const
Drizzle TeamDTDrizzle Team / help
11mo ago
How to get schema name from table name?
Drizzle TeamDTDrizzle Team / help
10mo ago
How to get the name of the table
Drizzle TeamDTDrizzle Team / help
3y ago