title: Employee Manager Report - Sql Server
body: <p>I have the below table</p>
  
  <pre><code>empid   empname     managerID
  1          A          NULL
  2          B           1
  3          C           1
  4          D           2
  </code></pre>
  
  <p>The ddl is as under</p>
  
  <pre><code>Declare @t table(empid int, empname varchar(20), managerID int)
  insert into @t 
  
  select 1,'A',null union all
  select 2,'B',1 union all
  select 3,'C',1 union all 
  select 4,'D',2
  </code></pre>
  
  <p>What I have to do is to prepare a report which will indicate which employees report to which manager.</p>
  
  <p>I have soved it using </p>
  
  <pre><code>select EmpName = e.empname, ManagerName = m.empname
  from @t e 
  left join
  @t m
  on  e.managerID = m.empid  
  </code></pre>
  
  <p>and the desired output being</p>
  
  <pre><code>EmpName    ManagerName
  A          NULL
  B          A
  C          A
  D          B
  </code></pre>
  
  <p>What are the other ways of doing so?</p>