Using column alias in WHERE clause of MySQL query produces an error

后端 未结 8 1091
北荒
北荒 2020-11-22 03:40

The query I\'m running is as follows, however I\'m getting this error:

#1054 - Unknown column \'guaranteed_postcode\' in \'IN/ALL/ANY subquery\'

<
8条回答
  •  难免孤独
    2020-11-22 03:51

    You can only use column aliases in GROUP BY, ORDER BY, or HAVING clauses.

    Standard SQL doesn't allow you to refer to a column alias in a WHERE clause. This restriction is imposed because when the WHERE code is executed, the column value may not yet be determined.

    Copied from MySQL documentation

    As pointed in the comments, using HAVING instead may do the work. Make sure to give a read at this question too: WHERE vs HAVING.

提交回复
热议问题