Oracle's orthogonal difference function, Intersect;union;minus.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.