D J Horton Consulting Ltd

Personal reference to useful tips and tricks for SQL Server, SQL Server Reporting Services and Crystal Reports.

My alternative to scraps of paper lying about.

Tuesday, 10 November 2009

Self Join - SQL

Self join between two instances of the same table. For example, obtaining employees and their managers.

SELECT E.Name as emp, M.Name as mgr
FROM Employees as E
LEFT OUTER JOIN Employees as M
ON E.ParentID = M.EmployeeID

No comments: