title: Update statement with self join in sybase
body: <p>I have one table which contain following data.</p>
  
  <pre><code>Emp_Id  Name    dept   cat
   1      abc             P
   1               HC     G
   2      def             P 
   2               ET     G
   3      ghi             P
   3               BC     G
   3               MN     G
   4      jkl             P
   4               LS     G
   4               LS     G
  </code></pre>
  
  <p>I want to update this table to have output records like.</p>
  
  <pre><code>Emp_Id     Name    dept    cat
       1      abc      HC     P
       2      def      ET     P
       3      ghi      BC     P
       4      jkl      LS     p
  </code></pre>
  
  <p>if Emp_Id is associated with two different dept then it should update any one of the dept (Emp_Id=3). if one Emp_Id is associated with two same dept then it should come once (Emp_Id=4). 
  I am using below query</p>
  
  <pre><code>UPDATE Table1 
      SET a.dept = b.dept
      from Table1 a, Table1 b          
      WHERE
        a.Emp_Id=b.Emp_Id
        and a.cat='P'
  </code></pre>
  
  <p>but it is not updating anything for Emp_Id 3 and 4
  Can anyone help?</p>
  
  <p>Thanks,
  Dhiraj</p>