Subquery in select, and referencing value from outer query
Hello!
I am trying to convert this postgres query from SQL til drizzle syntax.
How do i use subqueries in select in drizzle? Is it correct to left join the subquery, matching on a FK and then selecting the property in the select? As described in this article: https://www.davegray.codes/posts/how-to-write-a-sql-subquery-with-drizzle-orm
// Note: The reason for using subquery in this case is because i am dealing with a large dataset and performance testing shows that joining is substantially slower than subqueries.
3 Replies
I've tried this: but i'm getting the error
error: invalid reference to FROM-clause entry for table "subscription_monthly_usage"
the first issue I see is that you have an aggregage function in you subquery (sum) without a
group by
clause. I'm guessing you want to group by id
I don't see anything else that's obviousHi.
Yes i found out yesterday that that was the case.