mysql: ERROR 1054 (42S22): Unknown column ... in 'where clause'
This is a wiki page. Be bold and improve it!
If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.
Using alias 'as'
Query:
SELECT field AS my_field FROM my_table WHERE my_field = 1;
would result in:
ERROR 1054 (42S22): Unknown column 'my_field' in 'where clause'
Aliases defined with
AS
can only be used with GROUP BY
, ORDER BY
, or HAVING
.
Corrected SQL:
SELECT field AS my_field FROM my_table HAVING my_field = 1;