开发者

How to use "as" to set alias for joined tables in oracle 10

开发者 https://www.devze.com 2023-01-17 09:18 出处:网络
I wrote this, and it is wrong syntax, help me fix it, I want \'T\' to be an alias of the result of the two inner joins.

I wrote this, and it is wrong syntax, help me fix it, I want 'T' to be an alias of the result of the two inner joins.

se开发者_如何学JAVAlect T.id 
from table1 
  inner join table2 on table1.x = table2.y  
  inner join table3 on table3.z = table1.w as T;


You cannot use aliases to name the "entire" join, you can, however, put aliases on individual tables of the join:

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

In the projection, you will have to use the alias of the table, which defines the id column you are going to select.


You can't directly name the result of a join. One option is to use a subquery:

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

Another option is subquery factoring:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消