本次來寫個SQL 資料庫的部份
目的要將兩個table合併成一個
且 欄位不同 ,資料有部份相同
範例:
tableA
col0 col1 col2
--------------------------
AA0 AA0 AAA0
AA1 AA1 AAA1
tableB
col0 col3 col4
--------------------------
BA0 BA0 BAA0
BA1 BA1 BAA1
AA0 AA0 AAA0
SELECT Col1 as name1 ,Col2 as name2
From tableA
Where 條件....
UNION
SELECT Col3 as name1 ,Col4 as name2
from tableB
where 條件.....
結果
table
name1 name2
--------------------------
AA0 AAA0
AA1 AAA1
BA0 BAA0
BA1 BAA1
0 意見