SELECT first_name,department_name
FROM employees,departments
WHERE employees.department_id=departments.department_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非等值连接
角度二:自连接(自我引用)vs非自连接
*/
# 角度1:等级连接vs非等值连接
SELECT * FROM job_grades;
#查询名字,月薪和对应等级
SELECT last_name,salary,grade_level
FROM employees,job_grades
WHERE employees.salary BETWEEN job_grades.lowest_sal AND job_grades.highest_sal;
SELECT last_name,salary,grade_level
FROM employees,job_grades
WHERE employees.salary >= job_grades.lowest_sal AND employees.salary <=job_grades.highest_sal;
#角度二:自连接(自我引用)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;