SELECT last_name,department_name
FROM employees emp,departments dep
where emp.department_id=dep.department_id;
#如果有n个表实现多表查询,至少需要n-1 连接条件
#查询员工的employee-id,last_name,department_name,city
#等值连接
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;
/*
角度一 等值连接 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;