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;