将查询结果与另一个表连接

时间:2014-04-14 22:31:00

标签: sql oracle join

我有以下查询

Select TA.Column1 , COALESCE(TE.Column2,TA.Column2) as  Mydata

from TableA TA
INNER JOIN TableB TB ON (TA.Column2 =TB.Column1)
LEFT JOIN TableC TC ON (TB.Column2  = TC.Column1)
LEFT JOIN TableD TD ON (TC.Column1 = TD.Column1)
LEFT JOIN TableE TE ON(TD.Column2 = TE.Column1)

要获得我想要的结果,我需要Join MyData列与另一个TableX

例如INNER JOIN TableX TX ON (TableX.Column1 = MyData)并且在我的选择查询中有TableX.COlumn2

我的查询是如何将COALESCE(TE.Column2,TA.Column2) as Mydata获取的值加入表TableX

1 个答案:

答案 0 :(得分:0)

从表面上看,你应该能够做到这一点。 (你有没试过?)

Select TA.Column1 , COALESCE(TE.Column2,TA.Column2) as  Mydata, TX.Column2
from TableA TA
INNER JOIN TableB TB ON (TA.Column2 =TB.Column1)
LEFT JOIN TableC TC ON (TB.Column2  = TC.Column1)
LEFT JOIN TableD TD ON (TC.Column1 = TD.Column1)
LEFT JOIN TableE TE ON(TD.Column2 = TE.Column1)
LEFT JOIN TableX TX ON (COALESCE(TE.Column2,TA.Column2)) = TX.Column1