美文网首页MySQL
MySql in 和 exists

MySql in 和 exists

作者: ratil_ | 来源:发表于2018-01-02 16:48 被阅读0次

    in 的使用:

    in 在查询中表示查询in后面存在的值

    如: select * from A where id in (select age from A);

    id 会与 in 后面括号语句查询到的 age 的值一一匹配

    如果当 id 的值与 age相同,则会返回 id 的值,直到查到所有 id = age 的值

    最后打印出 id = age 的所有行。

    exists 的使用:

    exists 用于返回 truefalse

    如: select * from A where exists (select age from A);

    如果括号内语句 (select age from A) 查询到了语句, 则返回 true, 接下来前面的 select 会将表 A 的所有数据查询出来

    如果括号内语句 (select age from A) 查询没查询到语句, 则返回 false, 接下来前面的 select 将不会查询出语句

    相关文章

      网友评论

        本文标题:MySql in 和 exists

        本文链接:https://www.haomeiwen.com/subject/yakqnxtx.html