子查询

概念:查询中嵌套查询,称嵌套查询为子查询

-- 查询工资最高的员工信息

-- 1.查询最高的工资是多少 9000

select max(salary) from emp;

-- 查询员工信息,并且工资等于9000的

select * from emp where salary =9000;

-- 一条sql就完成这个操作 子查询

select * from emp where salary = (select max(salary) from emp);

子查询的不同情况

1.子查询的结果是单行单列的:

子查询可以作为条件,使用运算符去判断

-- 查询员工工资小于平均工资的人

select * from emp where salary < (select avg(salary) from emp);

2.子查询的结果是多行单列的:

子查询可以作为条件,使用运算符in来判断

-- 查询"财务部"和"市场部"所有的员工信息

select id from dept where name = "财务部" or name = "市场部";
select * from emp where dept_id = 3 or dept_id = 2;
-- 子查询
select * from emp where dept_id in (select id from dept where name = "市场部" or name = "财务部");

3.子查询的结果是多行多列的:

查询员工入职日期是2011-11-11日之后的员工信息和部门信息

select * from dept,(select * from emp where emp.join_date > "2011-11-11") t2 where dept.id = t2.dept_id;

最新文章

  1. linux(centOS)下安装Oracle步骤
  2. ios培训机构排名
  3. 使用TabPageIndicator的样式问题
  4. python学习笔记-Day6(1)
  5. sqlserver同步表的脚本
  6. 关于jsp利用EL和struts2标签来遍历ValueStack的东东 ------&gt; List&lt;Map&lt;K,V&gt;&gt; 以及 Map&lt;K,&lt;List&lt;xxx&gt;&gt;&gt; 的结构遍历
  7. Func 委托
  8. poj2411Mondriaan&#39;s Dream(状压)
  9. C#核编之字符串类型介绍与操作
  10. Code 16K 码
  11. 注册表中LEGACY残留项的清理技巧
  12. Swagger服务API治理详解
  13. RPO(Relative Path Overwrite)
  14. 初学Python——文件操作第三篇
  15. 在前台根据传过来的XX级别的数字转XX的名字
  16. Nginx源码结构及如何处理请求
  17. 2017-8-20 HTTP协议
  18. ICCV2013 录用论文(目标跟踪相关部分)(转)
  19. JS中的事件冒泡——总结
  20. [算法]用JAVA实现快速排序

热门文章

  1. Ansible的参数介绍
  2. a commponent required a bean of type XXXXXX that could not be found-2022新项目
  3. 零基础学Java第二节(运算符、输入、选择流程控制)
  4. 【多线程】守护线程 Daemon
  5. 【多线程】观测线程状态 getState()
  6. Python数据分析--Numpy常用函数介绍(2)
  7. Element UI DatePicker 时间跨度限制在同一个月内
  8. Windows环境下启动Redis报错:Could not create server TCP listening socket 127.0.0.1:6379: bind: 操作成功完成。(已解决)
  9. 值得注意的: c++动态库、静态库、弱符号__attribute__((weak))以及extern之间的关系
  10. MUI+html5的plus.webview页面传值在电脑浏览器上不可见