数据库——连接查询(子查询)
来源:互联网 发布:带数字的域名 编辑:程序博客网 时间:2024/05/31 11:03
准备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之装饰器学习
- leetcode 633. Sum of Square Numbers
- [Photon] 百度语音识别接入【Eclipse+Unity3D】
- 美团外卖广告投放系统的设计
- Spring Cloud在国内中小型公司能用起来吗?
- 数据库——连接查询(子查询)
- 多线程开山篇
- Unity3D集成腾讯语音GVoiceSDK
- oracle函数(1)
- Java中获取绝对路径出现% 20(路径被转码)的问题
- JavaWeb成长笔记(二)
- 在CentOS 7上安装Jenkins
- 5、Base64加密算法
- 大数据视觉智能实践及医学影像智能诊断探索(讲座精华笔记)