title: Employees and departments database query with Sql
body: <p>Suppose I have a junction table</p>
  
  <pre><code>EmployeeId  DeptId   
  ---------   ------
      1        1
      1        2
      1        3
      2        1
      2        2
      2        3   
      3        1
      3        2
      4        1
      5        2
      5        3
      6        1
      6        2
      6        3
  </code></pre>
  
  <p>So 1 employee can work in many departments</p>
  
  <p>My problem is to find which employee works in multiple departments?</p>
  
  <p>e.g.</p>
  
  <p>If I want to search an employee who works for department <code>1,2,3</code>, the result will be: <code>1,2,6</code></p>
  
  <p>If I want to search an employee who works for department <code>2 &amp; 3</code> the result will be <code>1,2,5,6</code></p>
  
  <p>If I want to search an employee who works for department <code>1 &amp; 2</code> the result will be <code>1,2 ,3,6</code></p>
  
  <p>I tried with the following queries</p>
  
  <pre><code>a) SELECT DISTINCT EmployeeId FROM dbo.EmpDept WHERE DeptId in (2,3) 
  </code></pre>
  
  <p>I got wrong result</p>
  
  <pre><code>b) SELECT DISTINCT EmployeeId FROM dbo.EmpDept WHERE DeptId = 2 AND  DeptId = 3
  </code></pre>
  
  <p>This time I got no records</p>
  
  <p>Please help me out.</p>
  
  <p><strong>N.B.</strong>~ I only simulated my real time project scenario. I cannot reveal the exact schema or table names or anything related to the project as it is confidential.</p>
  
  <p>Thanks in advance</p>