Kiwibe
Kiwibe
DTDrizzle Team
Created by Kiwibe on 10/11/2024 in #help
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))
šŸ™
4 replies