- UNION ALL將不會消除重複
- 在集合操作(UNION/INTERSECT/EXCEPT)中,別名從第一個查詢中獲取(目前我只知道一個異常 - Hive r equires別名是相同的所有查詢 - 我認爲這是一個bug)
select A as P, B as Q, C as R, D as S
from table1
union all
select W,X,Y,Z
from table2
+---+---+---+---+
| p | q | r | s |
+---+---+---+---+
| 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 |
+---+---+---+---+
表2與3列
select B as Q, C as R, D as S
from table1
union all
select X,Y,Z
from table2
+---+---+---+
| q | r | s |
+---+---+---+
| 2 | 3 | 4 |
| 6 | 7 | 8 |
+---+---+---+
或
select A as P, B as Q, C as R, D as S
from table1
union all
select null,X,Y,Z
from table2
+--------+---+---+---+
| p | q | r | s |
+--------+---+---+---+
| 1 | 2 | 3 | 4 |
| (null) | 6 | 7 | 8 |
+--------+---+---+---+
當Table2只有3列時會發生什麼 - X,Y,Z?我是否也應該在這種情況下使用UNION ALL? – Sagar
查看編輯答案 –
感謝您的快速回復。 – Sagar