Skip to content
Advertisement

How can I use a calculated value in the WHERE clause?

I have the following SQL:

And I get the following error in phpMySQL:

How can I use the calculated value age in the WHERE clause?

Advertisement

Answer

In sql you can’t use alias in where clause (you must repeat the column code )

but you could create a view

and then

or apply the condition to an having clause

In sql there the cluases are evalueated in a specific order
the where condition is evaluated before select clause (so the column alias name in not know in this phase) instead the having clause is evaluated after the select clause

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement