1. 自连接:将一张表作为两张表看待进行的连接

    FROM table t1 JOIN table t2 ON t1.col = t2.col

    ①查询整个员工表select * from emp;

    Oracle数据查询(多表查询)

    ②查询员工的姓名和他对应的管理者的姓名

    select w.ename,m.ename from emp w join emp m on w.mgr = m.empno;

    Oracle数据查询(多表查询)

2. 外连接:使用空行匹配非匹配行的连接 

    FROM table1 [<LEFT | RIGHT | FULL> OUTER] JOIN table2ON t1.col = t2.col

    ①查询整个部门表select * from dept;

    Oracle数据查询(多表查询)

    ②右外连接:右边表全部显示,左边的表用空行匹配没有匹配的行。

  select ename,d.deptno,dname from emp right outer join dept d on emp.deptno = d.deptno  

             Oracle数据查询(多表查询)


    ③左外连接:左边的表全部显示,右边的表用空行匹配没有匹配的行。

    select ename,d.deptno,dname from emp left outer join dept d on emp.deptno = d.deptno

Oracle数据查询(多表查询)

    ④完全外连接:两边的表都会用空行匹配非匹配的行。

    select ename,d.deptno,dname from emp full outer join dept d on emp.deptno = d.deptno

Oracle数据查询(多表查询)


3. 连接更多表

FROM table1 JOIN table2 ON t1.col = t2.col

                     JOIN table3 ON t1. col= t3.col

select ename,dept.deptno,dname,grade
from emp join dept on emp.deptno = dept.deptno
         join salgrade on sal BETWEEN losal AND hisal;

Oracle数据查询(多表查询)




    

相关文章:

  • 2021-08-24
  • 2021-05-20
  • 2021-04-29
  • 2022-02-18
猜你喜欢
  • 2021-04-02
  • 2021-06-15
  • 2021-07-17
  • 2021-11-08
  • 2021-09-08
  • 2022-02-25
  • 2021-11-29
相关资源
相似解决方案