Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refer to a column name alias in the WHERE clause [duplicate]

I have written down this query in postgres sql with column alias it is working fine:

select email as e from users 

It displays me result under e column alias but when I fire where condition with e then it shows this error:

select email as e from users where e = '[email protected]'

ERROR: column "e" does not exist

Why so? How we can use alias in where condition?

like image 564
Harman Avatar asked Dec 04 '22 03:12

Harman


1 Answers

where is evaluated before select, so you can't use alias declared in select in where clause.

like image 77
potashin Avatar answered Dec 21 '22 22:12

potashin