In this lesson we are going to study about Self joins in a database.
Self Join:
Example:-To find the name of Abhishek and Aritra manager we need to
sql query :-
In simulate two table in the from clause there are two aliases ,namely emp and manager for the same table ,EMPLOYEE.
Related Article
Self Join:
- In order to join a table to itself we use the self join.
- This type of join is used to compare values between two columns in the same table .
Example:-To find the name of Abhishek and Aritra manager we need to
- find in EMPLOYEE table by looking the Emp_name columns.
- find the manager number from Manager_id.
- find the name of manager with manager_id.
sql query :-
select
emp.Emp_Name
as Employee_name,
manager.Emp_Name
as manager_name
from employees emp,
employees manager
where emp.manager_id=manager.emp_id
OUTPUT:
Related Article
- Join
- Cross Join
- Equi Join
- Non Equi Join
- Natural Join
- Join with Using clause.
- Join with ON clause
- Outer Join