Bug #78361 Column alias can be used in subquery in select list in the same query
Submitted: 8 Sep 2015 7:08 Modified: 24 Oct 2015 18:08
Reporter: Su Dylan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.6.22, 5.6.26 OS:Any
Assigned to: CPU Architecture:Any

[8 Sep 2015 7:08] Su Dylan
Description:

Result:
=======
mysql> SELECT 1 as a, ( select a+1 ) FROM (SELECT 1) t;
+---+----------------+
| a | ( select a+1 ) |
+---+----------------+
| 1 |              2 |
+---+----------------+
1 row in set (0.00 sec)

mysql> select version();
+------------+
| version()  |
+------------+
| 5.6.22-log |
+------------+
1 row in set (0.00 sec)

Problems:
=========
As document says, column alias can be used in GROUP BY, ORDER BY, HAVING clauses. Here, usage of column alias "a" in the subquery in the select list should not be allowed.

How to repeat:
SELECT 1 as a, ( select a+1 ) FROM (SELECT 1) t;

Suggested fix:
usage of column alias "a" in the subquery in the select list should not be allowed.
[8 Sep 2015 9:29] MySQL Verification Team
Hello Su Dylan,

Thank you for the report.

Thanks,
Umesh
[24 Oct 2015 18:08] Erlend Dahl
Fixed in 5.7.8, 5.8.0 under the heading of Bug#19823076.