Oracle collection Query

Source: Internet
Author: User

Union
Select * from emp where deptno = 10 union select * from emp where deptno = 20;
Select * from emp where deptno = 10 union all select * from emp where deptno = 20;
Select * from emp where ename like '% A %' or ename like '% M % ';
Select * from emp where ename like '% A %' union ename like '% M %'; // remove all parts
Select * from emp where ename like '% A %' union all ename like '% M %'; // do not remove
Intersection
Select * from emp where ename like '% A %' intersect ename like '% M %'; // common parts
Difference set
Belongs to first, not belongs to second
The Order by clause can only appear in the last statement. The column name or alias accepted by the first select statement
The column name of the query result must be the same as the column name of the first select statement.
Select * from (select * from emp where sal between 700 and 1300 union select * from emp where sal between 1200 and 1400) order by sal desc;
Select ename, sal from emp where sal between 700 adn 1300 union select ename, sal from emp where sal between 1200 and 1400 order by sal deces;
In the select statement, the parameter types and numbers must be consistent.
Brackets can be used to change the sequence of execution of the set.
The set operation uses the header of the first statement as the header.


From Zhang Xiaocong's column

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.