Martijn van Oosterhout <kleptog@xxxxxxxxx> writes: > You can't. Conceptually, the result of the SELECT is not visible until > *after* the WHERE clause has executed, so having the where clause > depend on the select won't work. It's not only conceptual. Consider SELECT 1/x FROM mytab WHERE x <> 0; You'd be unhappy if this query failed with a divide-by-zero error (and it would be a violation of the SQL spec, too). So per spec, the SELECT list must not be evaluated until after WHERE completes, and that's why it's not reasonable for WHERE to refer to the SELECT list. (Now, we've kinda broken this rule by allowing GROUP BY to refer to SELECT items, but that's a matter for another discussion.) regards, tom lane