如何在子查询中使用外部列

Mic*_* DN 5 sql oracle subquery

我有以下查询-

select * from 
Table1 t1 , table2 t2 ,
(select idCol from table3) t3
Run Code Online (Sandbox Code Playgroud)

我的问题是 - 我可以在子查询中使用表 t2 吗?

像这样

select * from 
Table1 t1 , table2 t2 ,
(select idCol, t2.nameCol from table3) t3
Run Code Online (Sandbox Code Playgroud)

显然这会产生错误invalid identifier t2.nameCol

但如果我写如下,它会给出不必要的额外行

select * from 
Table1 t1 , table2 t2 ,
(select idCol,  t2.nameCol from table3, table2 t2) t3
Run Code Online (Sandbox Code Playgroud)

还有其他方法可以做到这一点吗?

编辑

基本上我想要实现的目标是

select * from 
Table1 t1 , table2 t2 ,
(select 
    case
    when t2.nameCol = 'ABC'  then 'ABC'
    else idCol
    end idCol from table3) t3
Run Code Online (Sandbox Code Playgroud)

Tho*_*ner 0

仅当满足特定条件时才连接表称为外连接。具体方法如下:

select *
from table1 t1 
inner join table2 t2 on <join criteria here>
left outer join table3 t3 on t2.namecol <> 'ABC' and <join criteria here>;
Run Code Online (Sandbox Code Playgroud)

但是,在您的情况下,将子查询移至 SELECT 子句可能就足够了:

select 
  t1.*, 
  t2.*, 
  case when t2.namecol = 'ABC' then 
    'ABC' 
  else 
    (select idcol from table3 t3 where <join criteria here>) 
  end
from table1 t1 
inner join table2 t2 on <join criteria here>;
Run Code Online (Sandbox Code Playgroud)