多张写法,列出两个:
方法一:多表关联
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');
这种join..on的写法有什么特别的好处么?
欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) | Powered by Discuz! X3.2 |