• mysql 数据操作 多表查询 子查询 带EXISTS关键字的子查询


    带EXISTS关键字的子查询

    EXISTS关字键字表示存在。

     

    EXISTS 判断某个sql语句的有没有查到结果 有就返回真  true 否则返回假 False

    如果条件成立 返回另外一条sql语句的返回结果

     

    返回结果了

     

    mysql> select * from employee where  EXISTS(select id from department where name='技术');
    +----+------------+--------+------+--------+
    | id | name       | sex    | age  | dep_id |
    +----+------------+--------+------+--------+
    |  1 | mike       | male   |   18 |    200 |
    |  2 | alex       | female |   48 |    201 |
    |  3 | jack       | male   |   38 |    201 |
    |  4 | yuanhao    | female |   28 |    202 |
    |  5 | liwenzhou  | male   |   18 |    200 |
    |  6 | jingliyang | female |   18 |    204 |
    +----+------------+--------+------+--------+
    6 rows in set (0.00 sec)

     

    子查询也查不出结果 exists 返回是false

    mysql> select * from employee where  EXISTS(select id from department where name='it');
    Empty set (0.00 sec)

     

  • 相关阅读:
    【AngularJS】学习资料
    Anaconda环境安装
    ORM表之间高级设计
    drf序列化和反序列化
    安装与使用django-restframework
    django-restframework
    顶象滑块验证码
    Restful接口规范
    Web API接口
    BBS配置
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/9897877.html
Copyright © 2020-2023  润新知