title: Updating MySQL primary key
body: <p>I have a table <code>user_interactions</code> with 4 columns: </p>
  
  <pre><code> user_1
   user_2
   type
   timestamp
  </code></pre>
  
  <p>The primary key is <code>(user_1,user_2,type)</code><br>
  and I want to change to <code>(user_2,user_1,type)</code>  </p>
  
  <p>So what I did was :   </p>
  
  <pre><code>drop primary key ...  
  add primary key (user_2,user_1,type)...
  </code></pre>
  
  <p>and voila...  </p>
  
  <p>The problem is that database is live on a server.  </p>
  
  <p>So before I could update the primary key, many duplicates already crept in, and they are continuously creeping in.  </p>
  
  <p>What to do?  </p>
  
  <p>What I want to do now is to remove duplicates and keep the ones with the latest <code>timestamp</code> (which is a column in the table).  </p>
  
  <p>And then somehow update the primary key again.  </p>