六、子查询——多行子查询

六、子查询——多行子查询

1.什么是多行子查询

子查询结果为一列值,主查询与子查询之间使用in、not  in、any、all等连接。

2.多行子查询实例

(1)示例1

查询有成绩的同学的基本信息

<1>从成绩表中查询所有学生成绩不为空的学号

select student_id from student_score where score is not null;

<2>从学生表中查询所有基本信息【总的SQL语句】

select * from student 
where student_id in (select student_id from student_score where score is not null);

(2)示例2

查询没有成绩的同学的基本信息

<1>从成绩表中查询所有学生成绩不为空的学号

select student_id from student_score where score is not null;

<2>从学生表中查询所有基本信息【总的SQL语句】

select * from student 
where student_id not in (select student_id from student_score where score is not null);

3.注意点

尽量减少使用not in,效率不高。


解锁课程,学习更多mysql知识:
https://study.163.com/course/courseMain.htm?courseId=1209590958&share=2&shareId=400000000537035

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值