So it turns out that MySQL will, in certain circumstances, allow for duplicate table aliases to be used, eg:
SELECT
t1.a,
t2.b
FROM
test1.t1 AS tbl
JOIN test2.t2 AS tbl
WHERE
t1.a = 5
AND t2.b = 'foo';
If you look at what the parser sees this as (using a 'show warnings;' immediately after an 'explain extended') then you will see that it actually replaces those aliases, so it kind of works. However, this is still ugly and makes me cringe a little. I would never have thought it would be allowed until I came across it in a live query yesterday.
Ultimately, it may be documented in some dark corner as a feature but I filed a bug report on it anyway.
So the rules appear to be these:
1 - The two tables must be in different databases.
2 - There may not be any duplicate column names referenced in any part of the query.
Ammon
No comments:
Post a Comment