SELECT e.employee_id,d.department_name
FROM employees e,departments d
WHERE e.department_id=d.department_id;
#角度三:内连接 vs 外连接!
#咱们之前写的都是自连接
SELECT * FROM employees;
#我们只是把左边与右边的表满足条件的数据
#外连接的分类:左外连接 右外连接 满外连接
#外连接去做的话,涉及两个语法SQL92和SQL99(查询所有员工ID和部门名称)
#11111 先看sql92实现外连接
#之前用的都是SQL92的自连接
#92语法实现外连接:使用 +
SELECT e.employee_id,d.department_name
FROM employees e,departments d
WHERE e.department_id=d.department_id(+);
#SQL92 实现外连接 左外连接 使用 + 不能实现
#2222 SQL99 内连接
#可以在join前面加inner但是可省略
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;
#SQL99实现外连接
#查询所有员工ID和部门名称
#左外连接(OUTER可以去掉)
SELECT employee_id,department_name
FROM employees e LEFT OUTER JOIN departments d
on e.employee_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;
#满外连接