4

最初のテーブルには 3 つの列があり、2 番目のテーブルには最初のテーブルに存在する 1 つの列と追加したい 2 つの列があります。

元:

select  c1 as col1, c2 as col2, c3 as col3
from    Table1
union
select  c1, c4 as col4, c5 as col5
from    Table2

expected Result:

col1,col2,col3,col4,col5
4

2 に答える 2

3

あなたはすでにその質問をして、答えを得ました - https://stackoverflow.com/questions/18923218/unioning-tables-with-different-number-of-columns/18923250#18923250実際に結合ではなく結合が必要な可能性はありますか:

select
    t1.c1 as col1,
    t1.c2 as col2,
    t1.c3 as col3,
    t2.c4 as col4,
    t2.c5 as col5
from Table1 as t1
    inner join Table2 as t2 on t2.col1 = t1.col1
于 2013-09-21T14:10:36.433 に答える