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
Angelelz
Angelelz12mo ago
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Angelelz
Angelelz12mo ago
You might need to not alias the outer query Actually, you need to define an alias for the outer query
Angelelz
Angelelz12mo ago
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Want results from more Discord servers?
Add your server