To create a table and add data:
--Create Table_aCreate Tabletable_a (Avarchar2(Ten), Bvarchar2(Ten) );--add data to Table_aInsert intoTable_aValues('A1','B1'); Insert intoTable_aValues('A2','B2'); Insert intoTable_aValues('A3','B3'); --Create Table_bCreate TableTable_b (Avarchar2(Ten), Bvarchar2(Ten) );--add data to Table_bInsert intoTable_bValues('A1','B1'); Insert intoTable_bValues('A2','B2'); Insert intoTable_bValues('A4','B4');
Intersect: Returns the same part (intersection) of the query results.
SELECT from INTERSECT SELECT from table_b; -- Results A B------------A1 b1a2 B2
Union,union all: Returns the results of a query, union filters duplicates, and union all does not filter duplicates.
--table_a and Table_b will remove duplicate dataSELECTA, b fromtable_aUNION SELECTA, b fromTable_b; --ResultsA B------------A1 b1a2 b2a3 b3a4 b4--all data in table_a and Table_bSELECTA, b fromtable_aUNION All SELECTA, b fromTable_b;--ResultsA B------------A1 b1a1 b1a2 b2a2 b2a3 b3a4 b4
Minus: Returns data that is not included in the second query result in the first query result.
SELECT from Table_aminus SELECT from Table_b; -- Results A B-----------A3 B3
Oracle's orthogonal difference function, Intersect;union;minus.