当前位置:网站首页>SQL学习笔记九种连接2
SQL学习笔记九种连接2
2022-07-01 06:21:00 【小美元】
等值连接 vs 非等值连接
SELECT last_name,salary ,job_grades.grade_level from employees,job_grades
WHERE employees.salary >= job_grades.lowest_salAND employees.salary < job_grades.highest_sal;
外连接,内连接
左外连接,右外连接
-sql 92语法实现外连接
SELECT a.first_name,a.employee_id,a.department_id FROM employees a ,departments b
WHERE a.department_id = b.department_id(+);
-mysql不支持sql92语法-
-99语法左外连接
SELECT a.first_name,a.employee_id,a.department_id FROM employees a LEFT OUTER JOIN departments b
ON a.department_id = b.department_id;
outer可以省略掉
左外连接查出来的是左边的一整张图
右外连接是右边一整张图
union
由于sql中full join不能用到,因此使用union取两个表的并集
- union all 两个图a图和b图进行合并,重复部分多余有一份,虽然冗余,但是开发中尽量用union all

中图:内连接
SELECT a.first_name,a.employee_id,a.department_id FROM employees a JOIN departments b
ON a.department_id = b.department_id;
左上图
SELECT a.first_name,a.employee_id,a.department_id FROM employees a LEFT JOIN departments b
ON a.department_id = b.department_id;
右上图
SELECT a.first_name,a.employee_id,a.department_id FROM employees a RIGHT JOIN departments b
ON a.department_id = b.department_id;
左中图
SELECT a.first_name,a.employee_id,a.department_id FROM employees a LEFT JOIN departments b
ON a.department_id = b.department_id
WHERE a.department_id = NULL;
右中图
SELECT a.first_name,a.employee_id,a.department_id FROM employees a RIGHT JOIN departments b
ON a.department_id = b.department_id
WHERE b.deparment_id = NULL;
满外连接
左上图 UNION ALL 右中图
SELECT a.first_name,a.employee_id,a.department_id FROM employees a LEFT JOIN departments b
ON a.department_id = b.department_id;
UNION ALL
SELECT a.first_name,a.employee_id,a.department_id FROM employees a RIGHT JOIN departments b
ON a.department_id = b.department_id
WHERE b.deparment_id = NULL;
边栏推荐
- Application of IT service management (ITSM) in Higher Education
- Student attendance system for C language course (big homework)
- [summary of knowledge points] chi square distribution, t distribution, F distribution
- idea 好用插件汇总!!!
- C语言课设学生选修课程系统(大作业)
- FPGA - clocking -02- clock wiring resources of internal structure of 7 Series FPGA
- C#如何打印输出原版数组
- 阶乘约数(唯一分解定理)
- [ManageEngine] how to realize network automatic operation and maintenance
- Restframework-simplejwt rewrite authentication mechanism
猜你喜欢
![[network security tool] what is the use of USB control software](/img/cc/20fc1f35c139c52c5922727368b835.png)
[network security tool] what is the use of USB control software

【Unity Shader 消融效果_案例分享】

HCM Beginner (III) - quickly enter pa70 and pa71 to browse employee information PA10

Movable mechanical wall clock

To sort out the anomaly detection methods, just read this article!

IT服务管理(ITSM)在高等教育领域的应用

【#Unity Shader#Amplify Shader Editor(ASE)_第九篇】

Design of sales management system for C language course (big homework)

Understanding of C manualresetevent class

VS2019如何永久配置本地OpenCV4.5.5使用
随机推荐
MongoDB:一、MongoDB是什么?MongoDB的优缺点
Top 10 Free 3D modeling software for beginners in 2022
On siem
Redis安装到Windows系统上的详细步骤
基金定投是高风险产品吗?
Pychart configuring jupyter
Self confidence is indispensable for technology
连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?
webapck打包原理--启动过程分析
子类调用父类的同名方法和属性
端口扫描工具对企业有什么帮助?
Restframework-simplejwt rewrite authentication mechanism
浅谈SIEM
[enterprise data security] upgrade backup strategy to ensure enterprise data security
[unity shader ablation effect _ case sharing]
异常检测方法梳理,看这篇就够了!
[ManageEngine] terminal management system helps Huasheng securities' digital transformation
[automatic operation and maintenance] what is the use of the automatic operation and maintenance platform
To sort out the anomaly detection methods, just read this article!
【Unity Shader 描边效果_案例分享第一篇】