Oracle collection Query

Source: Internet
Author: User
For Oracle set query, the Orderby clause can only appear in the last statement. The column name or alias accepted by the first select statement

For Oracle set query, the Order by clause can only appear in the last statement. The column name or alias accepted by the first select statement

Homepage → Database Technology

Background:

Read News

Oracle collection Query

[Date: 2012-03-14] Source: Linux Author: java958199586 [Font:]

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.

  • 0
  • Oracle index Scanning

    Oracle Transaction Processing

    Oracle Database tutorial

    Image Information

    View All comments in this article (0)

    Comments

    Latest Information

    Popular this week

    Introduction to Linux community-advertisement service-website map-help Info-contact us
    The articles published on this site (LinuxIDC) do not mean that they agree with the statement or description. They only provide more information and do not constitute any suggestions.


    Copyright©2006-2011 Linux community All rights reserved Zhejiang ICP backup No. 06018118

    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.