数据库——连接查询(子查询)
来源:互联网 发布:iphone照片拷贝到mac 编辑:程序博客网 时间:2024/06/14 16:01
准备4张表:
# 子查询
-- any的用法
select num2 from t2 where num2 > any(select num1 from t1);
运行结果:
-- exists的使用(返回True,外层sql语句执行;返回False,外层sql不执行)
select * from score where exists (select name from student where s_id=20);#返回False
运行结果:
select * from score where exists (select name from student where s_id=101);#返回True
运行结果:
详解exists:
-- in的使用
-- select * from t1;# t1表
-- select * from t2;# t2表
-- select num1 from t1 where num1 in(select num2 from t2);
运行结果:
-- not in的使用(与in的用法相反)
-- select num1 from t1 where num1 not in(select num2 from t2);
运行结果:
-- union all的使用(使用union all包含重复的行;union从查询结果集中去除重复的行;)
select s_id,name from student where s_id>101 union all select s_id,name from student where s_id>103;
运行结果:
-- union的使用
select s_id,name from student where s_id>101 union select s_id,name from student where s_id>103;
运行结果:
select s_id,name from student where s_id>101 or s_id>103;
运行结果:
对比union和union-all的区别:
- 数据库——连接查询(子查询)
- 数据库——连接查询(子查询)
- mysql数据库子查询、连接查询——2014.5.27
- Mysql数据库查询语句DQL(Data Query Language)—— 连接查询、子查询、联合查询
- MySQL数据库学习——子查询与连接
- 数据库表的连接查询、子查询
- SELECT高级查询——连接查询、子查询
- 复杂查询(连接查询、子查询)
- 数据库——(10)联合查询和子查询
- 数据库SQL Server2012笔记(四)——多表查询、子查询、分页查询、用查询结果创建新表和外连接
- 数据库——(8)连接查询
- 数据库——连接查询
- Oracle数据库高级查询(四)子查询和连接查询的综合案例
- Mysql学习总结(8)——MySql基本查询、连接查询、子查询、正则表达查询讲解
- Mysql学习总结(8)——MySql基本查询、连接查询、子查询、正则表达查询讲解
- 连接查询和子查询(部分)
- MySQL——查询sql总结:简单查询、连接查询、子查询
- MySQL——查询sql总结:简单查询、连接查询、子查询
- 仿京东首页沉浸式图片以及状态栏变色
- Python数据挖掘-文本挖掘
- SCUT Training 20170913 Problem O
- 结构体指针
- shrio学习第二章
- 数据库——连接查询(子查询)
- github项目学习
- 使用dbms_shared_pool.purge清除共享池中的SQL执行计划
- jQuery日期选择器
- HDFS原理
- vs2013编译ffmpeg
- jQuery选择器的具体使用实例参考
- Git部分知识小结
- 170913_算法导论学习(一)_2.1 插入排序