凡事都在事上磨,这样才能精进,成长进步提高! ------ 博客园首页

exists 用法

exists 用法

exists 语法为:

select *
from table_a a
where exists (select 1 from table_b b where b.id = b.id);

exists 对外表用 loop 逐条查询,每次查询都会查看 exists 的条件语句。

当 exists 里的条件语句能够返回记录行时(无论返回多少记录行,只要能返回),条件就为真,返回当前 loop 到的这条记录。

反之如果 exists 里的条件语句不能返回记录行,则当前 loop 到的这条记录被丢弃。

exists 的条件就像一个 bool 条件,当能返回结果集则为 true,不能返回结果集则为 false

当子查询为 select NULL 时, mysql 仍然认为它是 True

posted @ 2024-08-14 17:18  追风fc  阅读(53)  评论(0)    收藏  举报