SQL nested subqueries inside and outside layers

Source: Internet
Author: User

Each row of the outer query is scanned line by row, and each row is compared to the internally queried table, which satisfies the return true of the where condition of the internal query and does not satisfy the return false.

Reminder: An error occurs when an internal query is executed separately.

Perform an external query first

Each row of the corresponding external query executes a subquery once, and the value of the current row in the outer query is referenced each time the subquery is executed.

Use the results of a subquery to determine the result set of an external query.

Cases:

Order information for the largest amount of orders handled by different employees

Select a.* from Order a WHERE amount = (select Max (amount) from order form where employee number =A. Employee number)

Employee information for the maximum wage in different warehouses

Select A.* from Employee a WHERE salary = (select Max (payroll) from worker where warehouse number = A. Warehouse number)

SQL nested subqueries inside and outside layers

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.