中图(内连接)
select employee_id, department_name
from employees e join departments d
on e.department_id = d.department_id;
左上图(左外连接)
select employee_id, department_name
from employees e left join departments d
on e.department_id = d.department_id;
右上图(右外连接)
select employee_id, department_name
from employees e right join departments d
on e.department_id = d.department_id;
左中图
select employee_id, department_name
from employees e left join departments d
on e.department_id = d.department_id
where d.department_id is null;
右中图
select employee_id, department_name
from employees e right join departments d
on e.department_id = d.department_id
where e.department_id is null;
左下图(满外连接)
方式一:左上图 union all右中图
select employee_id, department_name
from employees e left join departments d
on e.department_id = d.department_id
union all
select employee_id, department_name
from employees e right join departments d
on e.department_id = d.department_id
where e.department_id is null;
方式二:左中图 union all右上图
select employee_id, department_name
from employees e left join departments d
on e.department_id = d.department_id
where d.department_id is null
union all
select employee_id, department_name
from employees e right join departments d
on e.department_id = d.department_id;
右下图
左中图 union all右中图
select employee_id, department_name
from employees e left join departments d
on e.department_id = d.department_id
where d.department_id is null
union all
select employee_id, department_name
from employees e right join departments d
on e.department_id = d.department_id
where e.department_id is null;