加入teradata中的多个表

时间:2012-08-09 14:56:30

标签: sql database inner-join teradata

请帮我解决这个问题

sel a.col1,a.co2,a.col3,.........b.col1,b.col2..,c.col1,c.col2
from table1 as a inner join table2 as b on a.col1 =b.col1
inner join table3 as c on a.col1 = b.col1
where col1 = xxxxx;

现在我需要再加一个table table4。由于table4没有col1作为主索引,我需要将它连接到另一个具有主键的表。

以下是我需要在上述sel语句中加入的不同查询。

Sel xx.col1,yy.aaa,yy.bbb,zz.ccc,zz.ddd,zz.eee
from tablea as xx, tableb as yy, table4 as zz
where xx.col1 = yy.bbb and yy.aaa = zz.ccc

主要索引:

  • col1 for table1,table2,table3,tablexx
  • aaa for tableb
  • ccc for table4

提前致谢

1 个答案:

答案 0 :(得分:0)

怎么样:

Select a.leg,c.btn,p.prods,svc.sr,speed.test, a.leg, b.acct_id, e.emp_no, e.emp_name
FROM db1.tb1 as a 
    inner join db1.tb2 as C ON a.leg = C.leg 
    inner join db1.tb3 as p ON a.leg = p.leg 
    inner join db1.tb3 as svc on a.leg = svc.leg 
    inner join db2.tb4 as speed on a.leg = speed.leg
    inner join db4.tb1 as b on a.leg = b.sce_acct_id
    inner join db4.tb5 as e on b.acct_id = e.acct_id
where a.leg ='xxxx'