Oracle set operators union, union all, intersect, and minus

Source: Internet
Author: User


Oracle set operators union, union all, intersect, and minus go straight to the topic: if we need to display the results of the two select statements as a whole, we need to use the union or union all keyword. Union (or union) is used to display multiple results together. The difference between union and union all is that union will automatically compress the repeated results in multiple result sets, while union all will display all the results, whether they are repeated or not. Www.2cto.com 1. union: Perform union operations on two result sets, excluding duplicate rows and sorting by default rules. union All: Perform union operations on two result sets, including duplicate rows without sorting. intersect: intersection of two result sets, excluding duplicate rows, and sorting by default rules; 4. minus: performs the Difference Operation on two result sets, excluding duplicate rows, and sorts the default rules at the same time. You can specify the Order by clause in the last result set to change the sorting method. Example: 1. union: [SQL] SELECT * FROM emp WHERE sal <1500 UNION SELECT * FROM emp WHERE sal BETWEEN 1000 AND 2000 ORDER BY 1; www.2cto.com 2. union all: [SQL] SELECT * FROM emp WHERE sal <1500 UNION ALL SELECT * FROM emp WHERE sal BETWEEN 1000 AND 2000 ORDER BY 1;
3. intersect: [SQL] SELECT deptno FROM dept intersect select distinct deptno FROM emp; [SQL] DEPTNO ------ 10 20 30 www.2cto.com 4. minus: [SQL] SELECT deptno FROM dept minus select distinct deptno FROM emp; [SQL] DEPTNO ------ 40

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.