Oracle Getting Started sixth day (middle)--set operator (orthogonal difference set)

Source: Internet
Author: User

I. Overview

  What is the 1.SET operator? 

To concatenate multiple queries into a new query with the SET operator

      Union/union all--and set

      intersect--intersection

      minus--difference Set (a\b=a the elements in B are removed)

    For MySQL, the intersection, the difference set, reference : http://blog.csdn.net/goodleiwei/article/details/42149567

  2. Illustrations

   

second, intersection--union

Union intersection (automatic de-weight and requires two result set columns to be merged)

SELECT *  from employees1 UNION SELECT *  from Employees2

   UNION all does not go heavy:

SELECT *  from employees1 UNION  All SELECT *  from Employees2

    The sorting can be done in the following ways: (Because the department_id is the 11th column, so directly write the above number can)

SELECT *  from employees1 UNION SELECT *  from Employees2 ORDER  by  One

    You can also take a second layer of the wording, reference:https://www.2cto.com/database/201210/163404.html

  Of course, if the columns do not match, you can adjust them in the following form:

SELECT department_id, to_number (null) location        , hire_datefrom    EmployeesUNIONSELECT department_id, location_id,  to_date (null)  from   Departments;

SELECT employee_id, Job_id,salary  from    EmployeesUNIONSELECT employee_id, job_id,0from   job_ History

third, intersection--intersect

  

SELECT *  from employees1 INTERSECT SELECT *  from Employees2
Four, the difference set--minus

  

SELECT employee_id,job_id  from    employeesminusSELECT  employee_id,job_idfrom   job_history;

Oracle Getting Started sixth day (middle)--set operator (orthogonal difference set)

Related Article

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.