Self join - dotnet and db

Follow us on Facebook

SQL Server Mountain View Mountain View Mountain View

Wednesday, August 1, 2018

Self join




SELF JOIN is used to compare the table itself.
There is no any keyword “SELF” exists in SQL server.
LEFT/RIGHT/FULL keywords we can use for the self-join query. Here the LEFT and RIGHT tables both are same.

Syntax:
SELECT column_name(s)
FROM table1 t1
JOIN table1 t2
ON t1.column_name=t2.column_name; 

Example:
SELECT E.EmpIDE.EmpNameE.DeptIDE1.EmpName FROM tbl_Employees E  
[LEFT/RIGHT/INNER]JOIN tbl_Employees E1
ON E1.EmpID=E.ManagerID

Result
SelfJoin

No comments:

Post a Comment

x

Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.