2011-09-02 64 views
0
select t1Joint2.c1,t1Joint3.c3 from 
(select * from table1 where name = "some") t1, 
(select t1.c1,t2.c2 from table2 t2 where t1.c1 = t2.c2) t1Joint2, 
(select t1.c1,t3.c3 from table3 t3 where t1.c1 = t3.c3) t1Joint3, 
; 

以上查詢在Oracle中不起作用。
任何解決方法?Oracle:使用另一個子查詢的結果

使用Oracle 11g。

回答

1
with t1 as 
    (select * from table1 where name = 'some') 
, t1Joint2 as 
    (select t1.c1,t2.c2 from t1, table2 t2 where t1.c1 = t2.c2) 
, t1Joint3 as 
    (select t1.c1, t3.c3 from t1, table3 t3 where t1.c1 = t3.c3) 
select t1Joint2.c1,t1Joint3.c3 
from t1Joint2, t1Joint3 
; 
+0

我得到這個錯誤:ORA-00904:「T1」。「C1」:無效標識符 00904. 00000 - 「%s:無效標識符」 – dharm0us

+0

正在使用Oracle 11g。 – dharm0us

+0

@ dharm0us對不起,有一個小錯誤。我編輯了我的答案。現在它必須正常工作 – schurik

5

爲什麼不把它寫成:

select t1.c1, t3.c3 
from table1 t1 
join table2 t2 on t1.c1 = t2.c2 
join table3 t3 on t1.c1 = t3.c3 
where name = "some" 
+0

感謝。有用。 – dharm0us

相關問題