select employee_id,department_name
from employees e,departments d
where e. department_id=d.department_id;
# 角度三:内连接VS外连接
select * from employees;
#外连接的分类
# SQL92
#SQL92的内连接:见上
#SQL的外连接:使用+
#报错:这是因为MySQL不支持SQL92外连接
select employee_id,department_name
from employees e,departments d
where e. department_id=d.department_id(+);
#SQL99
#SQL99的内连接
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 inner join departments d
on e.department_id =d.department_id;
#加上city
select employee_id,department_name,city
from employees e join departments d
on e.department_id =d.department_id
join locations l
on d.location_id=l.location_id;
#左外连接
select employee_id,department_name
from employees e left outer join departments d
on e.department_id=d.department_id;
#outer可省略
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 outer join departments d
on e.department_id=d.department_id;
#右外连接
select 122-106;