title: Sybase SQL select statement to collapse and condense rows by an ID
body: <p>I need help constructing an SQL statement with Sybase to collapse rows linked by three columns, ID, Name and DEPT.  I have one table <code>TABLE1</code>:</p>
  
  <pre><code>ID    NAME     DEPT     CAT
  1     ghi                P
  1               CV       G
  2     abc                P
  2               IT       G
  2               HC       G
  3     def                P
  3     jkl                P
  3               ENT      G
  3               MC       G
  </code></pre>
  
  <p>The CAT column means category.  The P column means person.  The G column means group.  </p>
  
  <p><code>ID</code> can be person(NAME) as well as group(DEPT).  </p>
  
  <p>If ID(1) is associated with a person(NAME) as well as a group(DEPT) then I want to update the person(NAME) row to have DEPT name as well and then delete the group(DEPT) row.  If ID(2) is associated with one person(NAME) and more than one DEPT(group) then I want to have two rows for that NAME.  If ID(3) contains two different NAME and two different DEPT then I want separate rows for each NAME and DEPT as shown below:</p>
  
  <p>Below is the expected output I want:</p>
  
  <pre><code>    ID    NAME     DEPT     CAT
      1     ghi       CV       P
      2     abc       IT       P
      2     abc       HC       P
      3     def       ENT      P
      3     def       MC       P
      3     jkl       ENT      P
      3     jkl       MC       P
  </code></pre>
  
  <p>I would like an SQL statement that returns the above rows from <code>TABLE1</code>.  Is it possible?</p>