Bug #14721 Should be allowed to reference column alias in another column expression
Submitted: 7 Nov 2005 20:52 Modified: 14 Jun 2013 18:23
Reporter: Mike MySQLAB Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: Optimizer Severity:S4 (Feature request)
Version:4.1 OS:Any
Assigned to: CPU Architecture:Any

[7 Nov 2005 20:52] Mike MySQLAB
Column aliases cannot be referenced in the column list and I think that is wrong. I have complicated expressions in the column list and I'd like to reference them in other column expressions. As it stands, I have to repeat the expressions which can lead to mistakes if I don't update the expressions in both locations. Having the same column expressions in more than one location makes the query much harder to read.

How to repeat:
For example, the following should work but doesn't:
select 1+2 col1, 3+4 col2, col1+col2;

It complains "unknown column col1" in columns list. 

Suggested fix:
Why isn't MySQL smart enough to either reference col1, or copy the col1 expression internally for use by col1+col2?