mysql 資料操作 子查詢 帶EXISTS關鍵字的子查詢
阿新 • • 發佈:2018-11-02
帶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)