mysql exists与not exists实例详解
作者:zcqshine 时间:2024-01-24 22:57:14
mysql exists与not exists实例详解
tableA
|column1 | column1 |column3 |
tableb
|column1 | column1 |column3 |
要查询 tableA 的数据,条件是是 tableA.column1 不在 tableB 的 tableB.column2 中
也就是要得到类似以下语句的效果(not in 效果不完全等同于 not exists , 如果子查询中出现空记录, 则整个查询语句不会返回数据)
SELECT
a.*
FROM
tableA a
WHERE
a.column1 not in (
SELECT column2 FROM tableB
)
可以使用如下语句来实现
SELECT
a.*
FROM
tableA a
WHERE
NOT EXISTS(
SELECT b.column2 FROM tableB b WHERE a.colunm1=b.column2
)
以上只是两张表的情况, 其实在多张表的连接查询中也是比较好用的. 以上写法同样适用于exists
来源:https://my.oschina.net/zcqshine/blog/780871
标签:exists,mysql
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Go语言之嵌入类型详解
2024-02-05 08:39:16
![](https://img.aspxhome.com/file/2023/2/109692_0s.png)
Mysql systemctl start mysqld报错的问题解决
2024-01-26 03:41:45
![](https://img.aspxhome.com/file/2023/3/103573_0s.jpg)
MySQL数据库事务隔离级别详解
2024-01-26 12:34:03
VSCode远程SSH免密登录配置实现
2024-01-04 19:17:07
![](https://img.aspxhome.com/file/2023/9/117539_0s.png)
VueJs单页应用实现微信网页授权及微信分享功能示例
2024-04-16 09:35:50
![](https://img.aspxhome.com/file/2023/5/136585_0s.jpg)
PHP和JavaScrip分别获取关联数组的键值示例代码
2023-06-16 05:30:51
利用python绘制笛卡尔直角坐标系
2021-03-07 13:39:56
![](https://img.aspxhome.com/file/2023/5/101285_0s.png)
python实现自动登录
2023-10-20 05:11:46
![](https://img.aspxhome.com/file/2023/7/134867_0s.jpg)
Python中Json使用示例详解
2021-01-17 00:43:43
Python实现获取前100组勾股数的方法示例
2022-07-14 08:54:23
70+漂亮且极具亲和力的导航菜单设计推荐[译]
2009-02-23 13:15:00
![](https://img.aspxhome.com/file/UploadPic/up/2009022313285860.gif)
ORACLE隐藏参数查看及修改的方法
2024-01-13 02:33:27
vue3 axios 实现自动化api配置详解
2024-05-28 16:01:23
![](https://img.aspxhome.com/file/2023/9/123079_0s.jpg)
很有创意的鼠标指针风筝
2007-09-22 09:24:00
![](https://img.aspxhome.com/file/UploadPic/20079/22/200792292550972s.jpg)
PHP PDOStatement::getColumnMeta讲解
2023-06-22 08:34:14
Python 面向对象静态方法、类方法、属性方法知识点小结
2022-02-10 07:45:52
PHP无限分类代码,支持数组格式化、直接输出菜单两种方式
2024-05-13 09:24:51
你知道mysql哪些查询情况不走索引吗
2024-01-15 06:32:00
pyinstaller打包遇到的问题解决
2021-07-22 07:56:24
![](https://img.aspxhome.com/file/2023/3/101433_0s.jpg)
对python添加模块路径的三种方法总结
2023-11-26 04:01:35