mysql基础--Select语句-子查询

Select语句-子查询

子查询

指嵌入在其他sql语句中的select语句,也叫嵌套查询

  • 单行子查询:使用正常的关系表达符号 < > = !=
  • 多行子查询:使用关键字 in

用在where条件中:用来辅助筛选条件

用在from条件中:用来作为临时表一起组合返回结果数据,解决复杂问题非常有效

  • 使用all操作符:

    • select ename,sal, deptno from emp where sal > all(select sal from emp where deptno = 30)
    • 大于所有的为真
  • 使用any操作符:

    • select ename,sal, deptno from emp where sal > any(select sal from emp where deptno = 30)
    • 大于任意的为真
  • 多列子查询

    查询返回多个列数据

    (字段1,字段2) = (select 字段1,字段2 from ...)

    注意字段1和字段2对比时顺序要一致

posted @   邵泽龙  阅读(987)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示