Emp-Dept With Joins
Emp-Dept With Joins
Emp-Dept With Joins
deptno number(2,0),
dname varchar2(14),
loc varchar2(13),
constraint pk_dept primary key (deptno)
);
----------
-- inner join
select empno, ename ,sal, job, d.deptno , dname,loc
from emp e join dept d on e.deptno=d.deptno;
-- left join
select empno, ename ,sal, job, d.deptno , dname,loc
from emp e left join dept d on e.deptno=d.deptno;
-- right join
select empno, ename ,sal, job, d.deptno , dname,loc
from emp e right join dept d on e.deptno=d.deptno;
-- cortesion product/join
select empno, ename , job dname ,loc
from emp e , dept d order by 1;
=======================
create table country( code varchar2(100));
-- self join
=======================
select loc, ename , job , dname
from dept d right join emp e on d.deptno = e.deptno
minus
select loc, ename , job , dname
from emp e left join dept d on d.deptno = e.deptno;
==================
complex joins
=========================
-- inner join
select ename , dname , country
from emp e join dept d on e.deptno = d.deptno
join loc l on d.location_id = l.location_id;
--left join
select ename , dname , country
from emp e left join dept d on e.deptno = d.deptno
left join loc l on d.location_id = l.location_id;
--left join
select ename , dname ,LocName, country
from loc l left join dept d on l.location_id = d.location_id
left join emp e on e.deptno= d.deptno;
-right join
select ename , dname ,LocName, country
from emp e right join dept d on e.deptno= d.deptno
right join loc l on l.location_id = d.location_id