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 use of not exists in mysql

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

Share

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

This article mainly introduces the use of not exists in mysql, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

In mysql, "not exists" means that it does not exist. The condition judgment is made after the where, followed by the sub-query statement, which is judged according to whether the sub-query statement has the result or not. The syntax is "Select*from TableA a where Not Exists (sub-query statement)".

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

What is the use of not exists in mysql

Here we focus on Not Exists (similar to the use of Exists). Not Exists does not exist.

Usage:

Select * from TableA a where Not Exists (Select * from TableB b where a.id=b.id and a.name=b.name)

1. Not Exists is used after where, followed by a subquery statement (with parentheses)

2. Not Exists (Exists) does not care about the result of the subquery, but only about whether the subquery has a result.

3. The meaning of this sentence is to replace the records of TableA into the subquery one by one. If the subquery result set is empty, it means that it does not exist, then the TableA record appears in the final result set, otherwise it will be excluded.

Usage:

Select * from TableA a where Not Exists (Select 1 from TableB)

The query of this sentence is not empty under any circumstances, resulting in the final result set is empty, because the subquery corresponding to each record in TableA has a result set and the representation exists, so the final result set is empty.

Thank you for reading this article carefully. I hope the article "what is the use of not exists in mysql" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you 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