重庆思庄Oracle、Redhat认证学习论坛

标题: 【课堂笔记】【SQL】17.Retrieving Data Using Subqueries [打印本页]

作者: 5dm    时间: 2012-11-5 17:09
标题: 【课堂笔记】【SQL】17.Retrieving Data Using Subqueries

IN的主查询,成对比较。

……WHERE (manager_id,department_id) in ((1,2),(3,4),……);

 

标量子查询:

示例:

SQL> select employee_id,last_name from employees e
  2  order by (select department_name from departments d
  3  where e.department_id=d.department_id);

EMPLOYEE_ID LAST_NAME
----------- -------------------------
        205 Higgins
        206 Gietz
        200 Whalen
        100 King
        101 Kochhar
        102 De Haan
        112 Urman
        108 Greenberg
        109 Faviet
        110 Chen
        111 Sciarra

EMPLOYEE_ID LAST_NAME
----------- -------------------------
        113 Popp
        203 Mavris
        107 Lorentz
        105 Austin
        103 Hunold

 

关联子查询:

语句的解析过程如图

【课堂笔记】【SQL】17.Retrieving Data Using Subqueries
登录/注册后可看大图