SQL Tutorial : DRL / DQL - SELF JOIN
Let's learn about next topic: SELF JOIN
SELF JOIN:
***********
EMP MRG
EID LNAME MID EID LNAME MID
100 A - 100 A -
101 B 100 101 B 100
102 C 101 102 C 101
- SELECT E.EMPLOYEE_ID,E.LAST_NAME,M.EMPLOYEE_ID,M.LAST_NAME
FROM EMPLOYEES E,EMPLOYEES M
WHERE E.MANAGER_ID=M.EMPLOYEE_ID
- SELECT E.LAST_NAME,C.LAST_NAME
FROM EMPLOYEES E,EMPLOYEES C
WHERE E.DEPARTMENT_ID=C.DEPARTMENT_ID
AND E.EMPLOYEE_ID <>C.EMPLOYEE_ID AND E.DEPARTMENT_ID =20
No comments:
Post a Comment