课前回顾
SELECT e.employee_id,e.last_name,d.department_name,l.city
from employees e,departments d,locations l
WHERE e.department_id=d.department_id
and d.location_id=l.location_id;
SELECT e.employee_id,e.last_name,d.department_name,l.city
from employees e,departments d,locations l
WHERE e.department_id=d.department_id
AND d.location_id=l.location_id;
-- 多表查询的分类(归纳式)
-- 角度1:等值连接 vs 非等值连接
-- 角度2:自连接(自我引用) vs 非自连接
-- 角度3:内连接 vs 外连接
-- 角度1:等值连接 vs 非等值连接
SELECT * FROM job_grades;
-- 非等值连接
-- 查询名字,月薪对应的等级
SELECT e.last_name,e.salary,j.grade_level
FROM employees e,job_grades j
WHERE e.salary BETWEEN j.lowest_sal and j.highest_sal;
SELECT e.last_name,e.salary,j.grade_level
FROM employees e,job_grades j
WHERE e.salary>= j.lowest_sal
and e.salary<=j.highest_sal;
-- 角度2:自连接(自我引用) vs 非自连接
SELECT * FROM employees;
-- 查询员工id,员工姓名及管理者的id和姓名
SELECT e.employee_id,e.last_name,m. employee_id,m.last_name
from employees e,employees m #(将一个表抽象成两个表)
WHERE e.manager_id=m.employee_id;