Correlated subquery and non-correlated subquery

Source: Internet
Author: User

Correlated subquery and non-correlated subquery: the query name nested in other queries. A subquery is also called an internal query, while an external query (also called a primary query) contains the subquery statement ). All subqueries can be divided into two types: correlated subqueries and non-correlated subqueries. 1> non-correlated subqueries are subqueries independent of external queries. A subquery is executed once in total, after the execution is complete, the value is passed to the external query. 2> the execution of related subqueries depends on the data in the external query. If one row is executed in the external query, the subquery is executed once. Therefore, non-correlated subqueries are more efficient than related subqueries. query the names of employees whose salaries are higher than the average salaries of all employees: -- SELECT department_id for non-correlated subqueries, FIRST_NAMEFROM EMPWHERE DEPARTMENT_ID = 110AND SALARY> (select avg (SALARY) from empwhere DEPARTMENT_ID = 110);-The subquery is an independent query that queries the names of employees whose salaries are higher than the average salaries of their respective departments: -- SELECT E1.DEPARTMENT _ ID, E1.FIRST _ namefrom emp E1WHERE SALARY> (select avg (SALARY) from emp E2WHERE E2.DEPARTMENT _ ID = E1.DEPARTMENT _ ID) -Depends on the external query result order by E1.DEPARTMENT _ ID;

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.