The oracle set operation function set operator is used to merge the results of multiple select statements, including UNION, union all, INTERSECT, and MINUS. When using the set operator, make sure that the number of columns in Different queries matches the data type.
The set operator has the following considerations: * The set operator is not applicable to LOB, VARRAY, and nested columns. * The UNION, INTERSECT, and MINUS operators are not used for LONG columns. * If the selection list contains expressions or functions, the column alias must be defined for the expression or function. 1. UNION (UNION-free): When UNION is executed, duplicate rows in the result set are automatically removed and sorted in ascending order based on the results in the first column. 2. union all (with UNION set): duplicate rows are not removed and the result set is not sorted. 3. INTERSECT (intersection): obtains the intersection of the two result sets and sorts the results in ascending order in the first column. Select id, name, job from worker INTERSECT select empno, ename, job from emp; 4. MINUS (difference set): only shown in the first set, data that does not exist in the second collection. The results in the first column are sorted in ascending order. Select CUSTOMERNUMBER, DZMC, CREATETIME, LASTSENDTIME from userinfo hsu1, (select hsu. customerid, hsu. nameareainfoid from userinfo hsu where hsu. ispackage = 0 and hsu. SUBSTATUS = 0 and hsu. createtime <TO_DATE ('2017-03-05 ', 'yyyy-MM-DD') <p> MINUS select distinct hbr. customerid, hbr. nameid from revmagazineinfo hbr where hbr. SENDTIME <TO_DATE ('1970-03-05 ', 'yyyy-MM-DD') <p>) temp where hsu1.ISPACKAGE = 0 and hsu1.c Ustomerid = temp. customerid and hsu1.nameareainfoid = temp. nameareainfoid and hsu1.SUBSTATUS = 0 and hsu1.createtime <TO_DATE ('2017-03-05 ', 'yyyy-MM-DD') <p> SELECT * FROM (SELECT hsu. customerid, hsu. customernumber, hsu. MAGAZINEID, hsu. nameareainfoid FROM userinfo hsu WHERE hsu. ispackage = 0 AND (hsu. substatus = 0 OR hsu. substatus = 3) AND hsu. nameareainfoid IN (select distinct mi. nameid FROM magazineinfo Mi WHERE mi. pubtime <sysdate and mi. status = 1) and not exists (select 1 from revmagazineinfo hbr where hbr. customerid = hsu. customerid and hbr. nameid = hsu. nameareainfoid) 5. In addition, order by must be placed after the last select statement. When the column names are the same, they can be directly sorted by column names. If they are different, they can be sorted by position, you can also use aliases to make them the same. Select id, name x from new_emp union all select empno, ename x from emp order by x; // If the column names are not sorted by aliases, select id, name ename from new_emp union all select empno, ename from emp order by ename; // The column names are sorted by select id, name ename from new_emp union all select empno, ename from emp when aliases are not used at the same time; // after merging, the column name is displayed as the master table.