43.笔记 MySQL学习——EXISTS 和 NOT EXISTS子查询
2017-11-17 21:24
381 查看
43.笔记 MySQL学习——EXISTS 和 NOT EXISTS子查询
运算符EXISTS和 NOT EXISTS只会测试某个子查询是否返回了行。如果有返回,EXISTS为真,而NOT EXISTS结果为假。
mysql> select exists (select * from absence);
+--------------------------------+
| exists (select * from absence) |
+--------------------------------+
| 1 |
+--------------------------------+
1 row in set (0.00 sec)
mysql> select not exists (select * from absence);
+------------------------------------+
| not exists (select * from absence) |
+------------------------------------+
| 0 |
+------------------------------------+
1 row in set (0.00 sec)
在相关子查询中比较常见。
运算符EXISTS和 NOT EXISTS只会测试某个子查询是否返回了行。如果有返回,EXISTS为真,而NOT EXISTS结果为假。
mysql> select exists (select * from absence);
+--------------------------------+
| exists (select * from absence) |
+--------------------------------+
| 1 |
+--------------------------------+
1 row in set (0.00 sec)
mysql> select not exists (select * from absence);
+------------------------------------+
| not exists (select * from absence) |
+------------------------------------+
| 0 |
+------------------------------------+
1 row in set (0.00 sec)
在相关子查询中比较常见。
相关文章推荐
- Mysql学习笔记(九)索引查询优化
- MySQL学习笔记7(查询数据)
- MySQL学习笔记9:连接查询
- Mysql学习笔记(五)数据查询之测试sql部分。
- 13.笔记 MySQL学习——多表查询
- Mysql学习笔记八——子句查询
- MySQL学习笔记9:连接查询
- 41.笔记 MySQL学习——IN和NOT IN子查询
- MySQL学习笔记(5)——插入、查询记录
- Mysql学习笔记十——union查询
- Linux学习笔记:MySQL日常运维查询状态
- MySQL学习笔记7:基本查询
- MySQL中的基本查询语句学习笔记
- (MYSQL学习笔记2)多表连接查询
- 【学习笔记】mysql查询执行的基础
- MySQl学习记录3 :查询笔记
- mysql学习笔记之连接查询与子查询
- mysql学习笔记之九(多表数据记录查询)
- MySQL学习笔记(三)——多表查询
- Mysql查询高速缓存(学习笔记)