多张写法,列出两个:
方法一:多表关联
SQL> select e.last_name,d.department_id,d.department_name 2 from departments d join employees e on d.department_id=e.department_id 3 join locations l on d.location_id=l.location_id and l.city='Toronto';
LAST_NAME DEPARTMENT_ID DEPARTMENT_NAME ------------------------- ------------- ------------------------------ Hartstein 20 Marketing Fay 20 Marketing
方法二:子查询 select e.last_name,department_id,d.department_name from departments d join employees e using(department_id)
where d.location_id=(select location_id from locations where city='Toronto');
[此贴子已经被作者于2012-11-27 11:45:01编辑过] |