聯集:利用 "union" 達成.
交集:利用 "intersect" 達成.
差集:利用 "minus" 達成.
範例如下 :
程式碼
-- 建立 Temp Table CREATE TABLE TOM_1 ( A1 varchar(3) , qty number ); CREATE TABLE TOM_2 ( A2 varchar(3) , qty number ); -- 新增資料到 Temp Table Insert into TOM_1 values( 'A', 2 ); Insert into TOM_1 values( 'C', 3 ); Insert into TOM_1 values( 'E', 5 ); Insert into TOM_1 values( 'X', 3 ); Insert into TOM_2 values( 'A', 1 ); Insert into TOM_2 values( 'B', 2 ); Insert into TOM_2 values( 'C', 3 ); Insert into TOM_2 values( 'D', 4 ); Insert into TOM_2 values( 'X', 3 ); -- Union 結果: A, B, C, D, E, X Select A1 A from Tom_1 Union Select A2 A from Tom_2 Order by A; -- Intersect 結果: A, C, X Select A1 A from Tom_1 Intersect Select A2 A from Tom_2 Order by A; -- Minus (Table 1 - Table 2) 結果: E Select A1 A from Tom_1 Minus Select A2 A from Tom_2 Order by A; -- Minus (Table 2 - Table 1) 結果: B, D Select A2 A from Tom_2 Minus Select A1 A from Tom_1 Order by A; -- Drop Temp Table Drop Table Tom_1; Drop Table Tom_2;