select "masters".*, (select avg (rating)
from "reviews" where "master_id" = "masters"."id") as rating
from "masters" where rating > 3
[42703] ERROR: column "rating" does not exist
aliaspostgresql
select "masters".*, (select avg (rating)
from "reviews" where "master_id" = "masters"."id") as rating
from "masters" where rating > 3
[42703] ERROR: column "rating" does not exist
Best Answer
You can't use a column alias on the same level where you defined it. You need to wrap the query:
A more efficient solution is however, to do the aggregation once for all rows and then join to the result: