Bug #68902 Duplicate table aliases
Submitted: 9 Apr 2013 12:16 Modified: 9 Apr 2013 17:00
Reporter: Ammon Sutherland Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:5.1, 5.5, 5.0.97, 5.1.70, 5.5.32, 5.6.12, 5.7.1 OS:Any
Assigned to: CPU Architecture:Any
Tags: duplicate alias

[9 Apr 2013 12:16] Ammon Sutherland
Description:
Under certain conditions MySQL allows for using duplicate table aliases.  Requirements seem to be that the tables are in different databases and no column name is referenced which might be duplicated in both tables.

How to repeat:
CREATE DATABASE test1;
CREATE TABLE test1.t1 (a INT(1));
INSERT INTO test1.t1 VALUES(1);

CREATE DATABASE test2;
CREATE TABLE test2.t2 (b INT(1));
INSERT INTO test2.t2 VALUES(2);

SELECT * FROM test1.t1 tba;
+------+
| a    |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

SELECT * FROM test2.t2 tba;
+------+
| b    |
+------+
|    2 |
+------+
1 row in set (0.00 sec)

SELECT
   tba.a,
   tba.b
FROM
   test1.t1 tba
   JOIN test2.t2 tba;

Suggested fix:
Depends if this is a "feature" or an actual bug.  Right now it's allowed but can be considered pretty bad style.
[9 Apr 2013 17:00] Sveta Smirnova
Thank you for the report.

Verified as described.