How to use related subqueries in SQL Server

Source: Internet
Author: User

Subquery refers to embedding an SQL Sever statement into another SQL Sever statement. The database engine uses subqueries as virtual tables to perform queries. A subquery can be used as a table in a join statement and can be used as a value in a select statement, a SQL Sever query clause, or a statement of an SQL Sever query clause, it is mixed with data operation statements.

The execution of subqueries depends on nested queries. The query tree starts from the innermost layer and runs outward at the first layer. High-level nested queries can access the results of low-level nested queries.

What are related subqueries?

Different from classic subqueries, related subqueries depend on external queries. External queries are related to subqueries, especially in the where Statement of subqueries. The subquery method is to execute an external Query when the reference of an external query is found in the subquery, and return the result to the subquery. Then, perform the subquery operation on the result set returned by the external query.

Execution performance of related subqueries

Because the subquery in the related subquery is executed in the result set returned by the external query, its efficiency will definitely decrease. The performance of subqueries depends entirely on queries and related data. However, if the related subquery statements are written efficiently, the execution performance is better than those using several join and temporary tables.Program.

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.