Example of SQL Self Join

·

Emp Table

NameNull?Type
EMPNONOT NULLNUMBER(4)
ENAME
VARCHAR2(10)
JOB
VARCHAR2(9)
MGR
NUMBER(4)
HIREDATE
DATE
SAL
NUMBER(7,2)
COMM
NUMBER(7,2)
DEPTNO
NUMBER(2)


Use a join command to produce the following output


Managers and Emps
SMITH Manages No-One
ALLEN Manages No-One
WARD Manages No-One
JONES Manages SCOTT
JONES Manages FORD
MARTIN Manages No-One
BLAKE Manages ALLEN
BLAKE Manages WARD
etc


select e1.ename||' Manages '|| nvl(e2.ename,'No-One')
"Managers and Emps"
from emp e1, emp e2
where e1.empno = e2.mgr(+)

Live Traffic Feed

About this blog

Site Sponsors