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)