title: Select Parent and Child Records
body: <p>How do i select all the employees of a company and its child companies?</p>
  
  <p>Using SQL Server 2008</p>
  
  <p><strong>Employee</strong></p>
  
  <pre><code>Id | Name | CompanyId  
  </code></pre>
  
  <p><strong>Company</strong></p>
  
  <pre><code>Id | Name | ParentCompanyId  
  </code></pre>
  
  <p>Example:</p>
  
  <p>1   Microsoft  0</p>
  
  <p>2   Microsoft India  1</p>
  
  <p>3  Microsoft Spain  1</p>
  
  <p>I have this below query which gives only employees from Microsoft and not from Microsoft India &amp; Spain. </p>
  
  <pre><code>SELECT Id, Name FROM Employee WHERE CompanyId=1
  </code></pre>
  
  <p>I am not good in SQL. Help me on this. </p>