Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the difference between related subquery and unrelated subquery in database

Shulou Source: shulou.com Published: 2022-05-31 15:15:49 09月29日 Update

This article mainly explains "what is the difference between related subquery and non-related subquery in the database". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what's the difference between a related subquery and a non-related subquery in the database?"

Subqueries can be divided into related subqueries and non-related subqueries, and the execution order and relationship between them and the outer query are different.

Associated subquery:

In the associated subquery, the internal query is executed once for each row of data returned by the external query. In addition, the information flow of the associated subquery is two-way, each row of data from the external query passes a value to the subquery, and then the subquery executes for each row of data once and returns its records, and then the external query makes a decision based on the returned records.

Select * from dept d where exists (select * from emp e where e.deptno = d.deptno)

Features:

1. Execute the outer query first

2. Execute the inner layer query again

Unrelated subquery:

An unrelated subquery is a subquery independent of the external query, and the value is passed to the external query after the subquery is executed.

Select * from emp where sal = (select max (sal) from emp)

Features:

1. Execute the inner layer query first

2. Execute the outer query again

At this point, I believe you have a deeper understanding of "what is the difference between related subqueries and non-related subqueries in the database?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Query association data database middle pass outer layer line content inner layer characteristics learning different practical deeper between information flow interest two-way practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information NVidia Shulou Tech Info Linux Redmi