title: Do mass update on the table based on two different IDs
body: <p>I'm trying to do a mass update on my table <code>tbl</code></p>
  
  <p>This how the table looks like when I do a select statement</p>
  
  <pre><code>SELECT * FROM tbl
  </code></pre>
  
  <p>It returns this:</p>
  
  <p><img src="https://i.stack.imgur.com/z2UF7.png" alt="enter image description here"></p>
  
  <p>What I'm trying to accomplish is to do a single update where UID are different but CID are the same. If this criteria is true update the second UID and set it with the first UID and set the OLDUID where UID was updated with the same UID.</p>
  
  <p>So the output will be like this:</p>
  
  <p><img src="https://i.stack.imgur.com/k0mZb.png" alt="enter image description here"></p>
  
  <p>What I'm trying to accomplish here is if I do a select statement:</p>
  
  <pre><code>SELECT * FROM tbl where UID = 1
  </code></pre>
  
  <p>It should return both rows. I have tried to join the two table and then do the update, but every time I try to do a select statement before the update it returns more rows than expected.</p>
  
  <p>Any suggestions?</p>
  
  <p><strong>NOTE*</strong> this is just a sample table. The original table contains thousands of rows. Also there're will be times where I will have 3 or 4 different UIDs but ONE CID. The concept is still the same. Update the two rows with the first UID and set the OLDUID with the ones that were updated.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>There're cases where two rows will have the SAME CID but UID are also the SAME. In this case, I don't want to update and set the OLDUID.</p>
  
  <p>Here's an example:</p>
  
  <p><img src="https://i.stack.imgur.com/dQZQ6.png" alt="enter image description here"></p>
  
  <p>Here's the output:</p>
  
  <p><img src="https://i.stack.imgur.com/eX5TD.png" alt="enter image description here"></p>
  
  <p>In this case it should ignore and do nothing. All of the rows where UID = OLDUID are the same type.</p>