当前位置:网站首页>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;
边栏推荐
- 基金定投是高风险产品吗?
- libpng12.so. 0: cannot open shared object file: no such file or directory
- C# ManualResetEvent 类的理解
- C language course set up property fee management system (big work)
- 【Unity Shader 描边效果_案例分享第一篇】
- [summary of problem thinking] Why is the register reset performed in user mode?
- B-树系列
- 高阶-二叉搜索树详解
- Minio error correction code, construction and startup of distributed Minio cluster
- Movable mechanical wall clock
猜你喜欢

Student attendance system for C language course (big homework)

C language course set up property fee management system (big work)
![[ManageEngine] how to realize network automatic operation and maintenance](/img/8a/75332d3180f92c6a6482d881032bbf.png)
[ManageEngine] how to realize network automatic operation and maintenance

【KV260】利用XADC生成芯片温度曲线图

Async and await
![[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage](/img/54/f187e22ad69f3985d30376bad1fa03.png)
[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage

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

C语言课设学生信息管理系统(大作业)

记磁盘扇区损坏导致的Mysql故障排查

C language course set up salary management system (big homework)
随机推荐
JMM详解
Detailed steps for installing redis on Windows system
[ManageEngine Zhuohao] use unified terminal management to help "Eurex group" digital transformation
B-tree series
ManageEngine卓豪助您符合ISO 20000标准(四)
Factorial divisor (unique decomposition theorem)
Excel visualization
HCM Beginner (IV) - time
SQL中DML语句(数据操作语言)
SystemVerilog learning-10-validation quantification and coverage
交换机配置软件具有的作用
[unity shader custom material panel part I]
idea 好用插件汇总!!!
Self confidence is indispensable for technology
Movable mechanical wall clock
记磁盘扇区损坏导致的Mysql故障排查
Functions of switch configuration software
High order binary search tree
FPGA - clocking -02- clock wiring resources of internal structure of 7 Series FPGA
Picture server project test