Subquery Statement of Oracle

Source: Internet
Author: User


Subquery: if another query is included in a subquery, The subquery format is SELECT {DISTINCT} * | column name 1 alias 1, column name 2 alias 2, FROM table name 1 alias 1, table name 2 alias 2, (SELECT {DISTINCT} * | column name 1 alias 1, column name 2 alias 2, FROM table name 1 alias 1, table name 2 alias 2, {WHERE condition (s)} {group by grouping condition {HAVING grouping condition }}{ order by sorting field ASC | DESC, sorting field ACS | DESC ,}{ WHERE condition (s) (www.2cto.com SELECT {DISTINCT} * | column name 1 alias 1, column name 2 alias 2, FROM table name 1 alias 1, table name 2 alias 2, {WHERE condition (s)} {group by grouping condition {HAVING grouping condition }}{ order by sorting word Segment ASC | DESC, sorting field ACS | DESC ,}{ group by grouping condition {HAVING grouping condition }}{ order by sorting field ASC | DESC, sorting field ACS | DESC ,} all subqueries must write code in. Subqueries can be divided into the following types in operations: Single-Column subqueries: The returned structure is a column of content, with the highest probability of occurrence of a single-row subquery: multiple returns, it may be a complete multi-row subquery of records: Multiple records are returned. If two employees with the lowest salary exist in a department at this time, the program will produce an error. IN a subquery, the operator www.2cto.com inanyall in is used to define a query range. SELECT * FROM empWHERE sal IN (select min (sal) FROM emp group by deptno); ANY operation: = ANY: similar to the IN operator, SELECT * FROM empWHERE sal = ANY (select min (sal) FROM emp group by deptno);> ANY: smaller than the smallest value, SELECT * FROM empWHERE sal> ANY (select min (sal) FROM emp group by deptno); <ANY: smaller than the maximum value: SELECT * FROM empWHERE sal <ANY (select min (sal) FROM emp group by deptno); ALL operation:> ALL: SELECT * FRO greater than the maximum value M empWHERE sal> ALL (select min (sal) FROM emp group by deptno); www.2cto.com <ALL is smaller than the smallest value SELECT * FROM empWHERE sal <ALL (select min (sal) FROM emp group by deptno); For subqueries, you can also perform multi-column subqueries. A subquery returns multiple query columns at the same time. SELECT * FROM empWHERE (sal, NVL (comm,-1) IN (SELECT sal, NVL (comm,-1) FROM emp WHERE deptno = 20 );

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.