2013-07-10 28 views
0

目前我有這三個表,該結構非常相似如何顯示這些結果在一行在Oracle

table1:id1 name1 
table2:id2 name2 
table3:id3 name3 

我期望的結果將是

name1 name2 name3 
value1 value2 value3 

我嘗試使用聯合,在SQL是:

select name1 from table1 where id1 = '1' 
union select name2 from table2 where id2 = '2' 
union select name3 from table3 where id3 = '3' 

但結果證明是:

name1  
value1 
value2 
value3 
+0

你想從選擇_exactly_'ID1 = 1'和'ID2 = 2'和'ID3 = 3',還是有一些規則結合? – Passerby

+0

1,2,3將是從用戶輸入 – jbiao

+0

得到的參數還沒有解決嗎? –

回答

0
SELECT 
    (select name1 from table1 where id1 = '1'), 
    (select name2 from table2 where id2 = '2'), 
    (select name3 from table3 where id3 = '3') 
from dual; 
+0

這個作品,thx – jbiao

0
select name1,name2,name3 from table1,table2,table3 
where table1.id1=1 and table2.id2=2 and table3.id3=3; 

fiddle

+0

這工作得很好,不知道哪個更好 – jbiao

+0

http://stackoverflow.com/questions/2871576/performance-subquery-or-joining ..值得引薦。 –

+0

http://stackoverflow.com/questions/2577174/join-vs-subquery ..這也是。 –

相關問題