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

[打卡]MYSQL 3

2024-04-16 12:15:54
0
181

SELECT employee_id,department_name
from employees e,departments d
where e.department_id=d.department_id;

e.manager_id=d.manager_id;
SELECT * from employees;

#引出外连接可能有员工没有部门,也可能有员工没部门
#如果想把除了内连接的显示出来,还想吧其他内容显示出来即外连接

#外链接的分类,左外连接,右外连接,满外链接


#sql92 sql99

#sql92 内链接
SELECT employee_id,department_name
from employees e,departments d
where e.department_id=d.department_id;

#sql92 外连接(在mysql不能用)
SELECT employee_id,department_name
from employees e,departments d
where e.department_id=d.department_id(+);

#sql99 内链接
SELECT employee_id,department_name
from employees e join departments d
on e.department_id=d.department_id;
#INNER可省略
SELECT employee_id,department_name
from employees e INNER join departments d
on e.department_id=d.department_id;

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;

#sql99 左外链接
SELECT employee_id,department_name
from employees e left outer 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;

#sql99右外连接
SELECT employee_id,department_name
from employees e right JOIN
departments d
on e.department_id=d.department_id;

评论
意见反馈