2015-12-02 12 views
1

如果我已经TLB1为:将多个表中的一个

col1 

1 

2 

3 

现在我有TLB2为:

col2 col3 

4  Four 

5  Five 

6  SIX 

人无我有tlb3作为

col4   col5 

    sample14  sample15 

    sample24  sample25 

    sample34  sample35 

有什么可以的询问我是否想要结果为:

col1 col2 col3 col4  col5  

1  4  Four sample14 sample15 

2  5  Five sample24 sample25 

3  6  Six sample34 sample35 

我试着用:

select ((select * from tlb1), (select * from tlb2),(select * from tlb3)) T 

但这种失败。

请帮帮我。

+0

为什么你要完全无关的数据结合起来?如果表中的行数不同,该怎么办? – jarlh

+0

不同行数只是造成问题.. –

+0

是的,你看!仍然认为这是一个好主意? – jarlh

回答

3
with t1 as (select col1, row_number() over (order by col1) rn from tbl1), 
t2 as (select col2,col3, row_number() over (order by col2) rn from tbl2), 
t3 as ( select col4,col5, row_number() over (order by col4) rn from tbl3) 
select t1.col1,t2.col2,t2.col3,t3.col4,t3.col5 
from t1 full outer join t2 on t1.rn = t2.rn 
t3 full outerjoin t2 on t2.rn = t3.rn 

尝试这样的事情......

+0

是的,这对我来说有点帮助..如果有什么困难我会回到你身边 –

相关问题