> People frequently think that because ORDER BY can refer to the > output-column aliases, other clauses should be able to do it too, > but this is not so. Thank you very much for clearing that one up. Now I have a follow-up question. Let's assume that I want not only to evaluate a subquery for the WHERE-statement, but also want to fetch the result of this subquery. I think that this would be the correct way to do so: SELECT t2.id, (SELECT COUNT(id) FROM t4 WHERE t2_id = t2.id AND value=10) AS t4_num FROM t2 WHERE t2.active AND ( (SELECT COUNT(id) FROM t4 WHERE t2_id = t2.id AND value=10) <= 3 ) Will the subquery be evaluated twice, or is postgres smart enough to somehow cache the result from the first call of the subquery? Kind Regards Stanislav Raskin ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match