43.笔记 MySQL学习——EXISTS 和 NOT EXISTS子查询

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)

在相关子查询中比较常见。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

 

 

 

 

 

你可能感兴趣的:(mysql,数据库)