Using parent field on subquery for conditioning.
$query = "SELECT p1.id,
(SELECT COUNT(1)
FROM post_table p2
WHERE p2.parent_id = p1.id) as num_children
FROM post_table p1
WHERE p1.parent_id = 0";
I wanted to use the parent field for my condition on subquery. I keep on reading the docs but couldn't find any on how to do it.
3 Replies
You can do this no problem https://orm.drizzle.team/docs/select#select-from-subquery
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
You might need to not alias the outer query
Actually, you need to define an alias for the outer query
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.