MySQL 子查询-exists

子查询:

Exists(subquery)

判断依据:

如过子查询可以返回数据,则认为exists表达式返回真,否则,返回假。

 

涉及到了多个表,从一个表中获取到一些信息,然后

在另一个表中找到相同信息的记录。

 

Select * from teacher_class where exists (select * from teacher where

Teacher_class.id=t_id);

 

等同于

 

Select * from teacher_class where id in (select id from teacher);

 

两种方法的思路不一致:

Exists:

先获得每一条teacher_class记录的数据,然后获得id字段,去teacher

表内找到对应值,找到就符合条件。

In:

先获得所有t_id的可能性,得到一个t_id集合,再检索teacher_class数据时,判断当前的id是否在所获得的t_id集合内。

 

其中 t_id teacher 的字段,

Id teacher_class 的字段

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值