Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report