#查询员工的employee_id,last_name,department_name,city
select employee_id,last_name,department_name,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 last_name,salary,grade_level from employees,job_grades where salary between job_grades.lowest_sal and job_grades.highest_sal;
select e.last_name,e.salary,grade_level from employees e,job_grades j where e.salary >=lowest_sal and e.salary <=highest_sal;
# 角度2:自连接(自我引用) VS 非连接
select * from employees;
# 查询员工id,员工的姓名及其管理者的id和姓名
select emp.employee_id,emp.last_name,mgr.employee_id,mgr.last_name from employees emp, employees mgr where emp.manager_id = mgr.employee_id;
select * from employees;