mysq中的子查询
来源:互联网 发布:网络恐怖主义案例 编辑:程序博客网 时间:2024/06/07 16:28
**当一个查询是另一个查询的条件时,称之为子查询
子查询(按结果划分):
1.表子查询:多行多列 类似这种 select * from (select t1 from tab2 where id=1 ) 或者select id,name, (select one) as test from tab1
2.行子查询:一行多列
3.列子查询:多行一列
4.标量子查询:一行一列* 类似这种 select name from tab1 where id = 2;*
例如两个表tab1 tab2
tab1 id name age tab2_id1 a 11 22 b 20 43 c 18 14 d 16 3
*
> tab2 > id is_adult Occupation t1 > 1 1 大学 tab1 > 2 0 小学 tab1 > 3 0 高中 tab1 > 4 1 大学 tab1
比较运算符中的子查询
select * from tab1 where age=(select max(age) from tab1);
使用in的子查询
例如 查找在读大学的人员姓名
select name from tab1 where tab2_id in(select id from tab2 where Occupation = ‘大学’)
*
使用any的子查询
定义 当某个操作数(字段)对于该列子查询的其中任一个值,都满足该比较运算符,则就算满足条件
例如
select * from tab1 where id> any(select id from tab2);
取出结果为
tab1
id name age tab2_id2 b 20 43 c 18 14 d 16 3
只有tab1中 id值满足 大于 tab2中id其中的一个值,则条件成立
使用all的子查询
定义 当某个操作数(字段)对于该列子查询的其中所有值,都满足该比较运算符,则就算满足条件
例如
select * from tab1 where id>= any(select id from tab2);
运算结果
tab1id name age tab2_id4 d 16 3
some的子查询
与any 同义词
- mysq中的子查询
- mysq中的各类查询语句
- mysq高效查询语句
- Mysq查询优化器
- mysq 慢查询
- mysq 存储过程查询
- 开启mysq慢查询
- mysq l查询优化
- MySQ语句查询
- ORACLE中的子查询
- ORACLE中的子查询
- ORACLE中的子查询
- sql中的子查询
- HQL中的子查询
- 数据库中的子查询。
- Oracle中的子查询
- oracle 中的子查询
- mysql中的子查询
- 员工管理Java
- poj3525Most Distant Point from the Sea【半平面交求到凸多边形边界最远距离】
- 风机桨叶故障诊断(六) 利用自编码器进行特征学习
- median of two sorted arrays
- JAVA1
- mysq中的子查询
- 面试题7:用两个栈实现队列
- UITableView的简单实用
- CentOS 6.5 与 win7 双系统时间同步问题
- 同步工具类-闭锁CountDownLatch
- 简述Java内存泄露
- SCP 从服务器上传下载文件
- swift plist文件
- android的adb命令以及测试