2010-09-20 74 views

回答

7

您不能直接命名連接的結果。一種選擇是使用子查詢:

select T.id 
from (
    select * 
    from table1 
    inner join table2 on table1.x = table2.y 
    inner join table3 on table3.z = table1.w 
) T 

另一種選擇是子查詢分解:

with T as (
    select * 
    from table1 
    inner join table2 on table1.x = table2.y 
    inner join table3 on table3.z = table1.w 
) 
select T.id 
from T 
8

不能使用別名命名「整個」加入,你可以,但是,放在各個表的別名的加入:

select t1.id 
from table1 t1 
    inner join table2 t2 on t1.x = t2.y 
    inner join table3 t3 on t3.z = t1.w 

在投影,你將不得不使用表,它定義了id列你要select的別名。