You cannot use a column alias in an on
or where
clause. You can do:
select column1 as alias
from table1 tt inner join
table1 ts
on tt.column1 = ts.column1;
You could also do:
select alias
from (select column1 as alias
from table1
) tt inner join
table1 ts
on tt.alias = ts.column1;
During the compile phase, the queries are evaluated by clause, with the from
clause first, then then where
and select
. In other words, the compiler doesn't "know" what is in the select
when it evaluates the from
.