Refer to a column name alias in the WHERE clause

2.6k Views Asked by At

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?

1

There are 1 best solutions below

1
On

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