您可以用union all
和group by
或full outer join
這樣做。因爲你有兩個以上的表格,union all
實際上更容易。你是對最終結果尚不清楚,所以這可能是足夠的:
select id, DDOCode, DesignationCode, BPS, Designation
from ((select id, DDOCode, DesignationCode, NULL as BPS, Designation
from table1
) union all
(select id, DDOCode, DesignationCode, BPS, Designation
from table2
) union all
(select id, DDOCode, DesignationCode, NULL as BPS, Designation
from table3
)
) t123
爲了您的精緻問題:
select distinct DDOCode,DesignationCode, Designation
from ((select id, DDOCode, DesignationCode, NULL as BPS, Designation
from table1
) union all
(select id, DDOCode, DesignationCode, BPS, Designation
from table2
) union all
(select id, DDOCode, DesignationCode, NULL as BPS, Designation
from table3
)
) t123;
我也想補充一點,所有的值必須是不同的,我的最終結果是隻有三個colums,I-E DDOCode,BPS,並指定 –
@KhuramJan。 。 。您的評論不清楚。哪些值?那是在把桌子放在一起之前還是之後? –
我也想添加一點,所有的值必須是不同的,我的最終結果是隻有三個colums,i-e DDOCode,BPS和指定 –