mysql – Unknown Column In Where Clause

mysql – Unknown Column In Where Clause

SQL is evaluated backwards, from right to left. So the where clause is parsed and evaluate prior to the select clause. Because of this the aliasing of u_name to user_name has not yet occurred.

What about:

SELECT u_name AS user_name FROM users HAVING user_name = john;

mysql – Unknown Column In Where Clause

See the following MySQL manual page:

A select_expr can be given an alias
using AS alias_name. The alias is used
as the expressions column name and
can be used in GROUP BY, ORDER BY, or
HAVING clauses.


It is not permissible to refer to a column alias in a WHERE clause,
because the column value might not yet be determined when the WHERE
clause is executed. See Section B.5.4.4, “Problems with Column

Leave a Reply

Your email address will not be published.