Mysql exists and not exists instances
Mysql exists and not exists instances
TableA
| Column1 | column1 | column3 |
Tableb
| Column1 | column1 | column3 |
To query the data of tableA, the condition is that tableA. column1 is not in tableB. column2 of tableB.
That is to say, to obtain the effect similar to the following statement (the not in effect is not exactly the same as not exists. If there is an empty record in the subquery, the entire query statement will not return data)
SELECT a. * FROM tableA aWHERE a. column1 not in (SELECT column2 FROM tableB)
You can use the following statement to implement
SELECT a. * FROM tableA aWHERE not exists (SELECT B. column2 FROM tableB B WHERE a. colunm1 = B. column2)
The above is only the case of two tables. In fact, it is quite useful in the connection query of multiple tables. The above method is also applicable to exists.
The above is a detailed explanation of mysql exists and not exists instances. If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article and hope to help you. Thank you for your support for this site!