What is a self join in SQL Server?
- It is a query in which two instances of the same table will be joined in the query.
- It is used to join a table to itself.
Syntax:SELECT a.column_name, b.column_name, …
FROM table1 a, table1 b
WHERE a.commonfield = b.commomfield;
Example:SELECT a.eId, b.eName, a.eSalary
FROM EMPLOYEE a, EMPLOYEE b
WHERE a. eSalary < b.Salary;