首页 小组 文章 相册 留言本 用户 搜索 我的社区 在线学堂 商城 购物车 支付钱包

[打卡]lululu 外连接

2024-04-16 15:04:15
0
126

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;

评论
此内容暂不接受评论!
意见反馈