带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)