Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the use of not exists in mysql

Shulou Source: shulou.com Published: 2022-05-31 11:07:49 10月03日 Update

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!

Tags: Query result sentence article meaning value interest sentence at the same time situation parenthesis tutorial more friend condition fruit version environment computer knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia Huawei Shulou Information Shulou Technology